替换CSV文件中的多个值

2024-06-28 20:03:02 发布

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

我有一个CSV文件,其中一列标题为“类型”。在本专栏下,我试图将价值观“福特”和“GMC”替换为“汽车”。我相信就我所拥有的而言,格式肯定有问题。请告知

df_jobs["Type"].replace(to_replace = "Ford", "GMC", value = "Automotive", inplace=True)

我得到的错误是

"SyntaxError: positional argument follows keyword argument"

Tags: 文件csvto标题类型df格式type
1条回答
网友
1楼 · 发布于 2024-06-28 20:03:02

错误是不言自明的"GMC"是一个位置参数,后跟to_replace = "Ford",这是一个关键字参数。
您需要的是列出"Ford""GMC",然后将其传递给to_replace键:

df_jobs["Type"].replace(to_replace = ["Ford", "GMC"], value = "Automotive", inplace=True)

相关问题 更多 >