【发布时间】:2018-11-02 09:03:54
【问题描述】:
我正在尝试使用以下代码按客户组连接多个 csv 文件:
files = glob.glob(file_from + "/*.csv") <<-- Path where the csv resides
df_v0 = pd.concat([pd.read_csv(f) for f in files]) <<-- Dataframe that concat all csv files from files mentioned above
问题是 csv 中的列数因客户而异,而且他们没有头文件。
我正在尝试查看是否可以根据该 csv 中的列数添加带有 col_1、col_2 等标签的虚拟标题列。
谁能指导我如何完成这项工作。谢谢。
关于尝试在 Dataframe 中搜索特定字符串的更新:
示例数据框
col_1,col_2,col_3
fruit,grape,green
fruit,watermelon,red
fruit,orange,orange
fruit,apple,red
试图过滤掉带有单词 red 的行,并期望它返回第 2 行和第 4 行。
尝试了以下代码:
df[~df.apply(lambda x: x.astype(str).str.contains('red')).any(axis=1)]
【问题讨论】:
标签: python-3.x pandas csv header