【发布时间】:2021-04-20 01:37:24
【问题描述】:
我正在尝试在由 .read_excel() 制成的 DataFrame 上使用 .replace()。尽管使用了 inplace = True,并且对拼写进行了三次检查(从原始 excel 文档中复制粘贴),该命令仍无法正常工作
import pandas as pd
def create_frame(path):
df1 = pd.read_excel(path)
return df1.replace(('Visit 2: Day 1','Day 1'), inplace = True)
df = create_frame('example.xlsx')
df.to_csv('test.csv')
我也尝试过使用 df2 = df1.replace(('Visit 2: Day 1','Day 1')) 而不是 inplace = True,但测试 csv 总是带有“访问 2:第 1 天”
.sort_values 和 .reset_index 也有类似的功能障碍(命令不起作用)。
任何想法我做错了什么?感谢所有帮助!谢谢!
【问题讨论】:
-
如果您在
replace中使用inplace = True,那么它将返回None,并且您的to_replace参数似乎格式错误,您究竟要替换什么?