如何在python中转换csv数据

2024-10-03 04:37:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个csv文件要转换。当前csv文件中的数据如下所示

115776 1142 1523 20197 20394 3421 1284 9572 19682 

但我希望它看起来像这样

^{pr2}$

。。。。。在

有什么办法吗?在

我现在写了一个函数来获取它,它是这样得到的

for row in read_csv(testfile, "Recipes_RecipeId Recipes_Ingredients_0_IngredientID Recipes_Ingredients_1_IngredientID Recipes_Ingredients_2_IngredientID Recipes_Ingredients_3_IngredientID Recipes_Ingredients_4_IngredientID Recipes_Ingredients_5_IngredientID Recipes_Ingredients_6_IngredientID Recipes_Ingredients_7_IngredientID Recipes_Ingredients_8_IngredientID".split()):
    with open('recipeIngredientID.csv', 'a') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=' ',
                            quotechar='|', quoting=csv.QUOTE_MINIMAL)
        spamwriter.writerow(row)

有没有更好的方法把它打印出来我想要它?在


Tags: 文件csv数据csvfile函数inforread