[英]How to extract data from a specific column in the first CSV file to another column in another CSV file?
I have two different CSV files which i have imported using pd.read_csv
.我有两个不同的 CSV 文件,它们是使用pd.read_csv
导入的。
Both files have different header names.这两个文件具有不同的 header 名称。 I would like to export this specific column under the header name of ["Model"]
in the first CSV file to the second CSV file under the header name of ["Product"]
我想将第一个 CSV 文件中["Model"]
的 header 名称下的这个特定列导出到["Product"]
的 header 名称下的第二个 CSV 文件
I have tried using the following code but produced value error:我尝试使用以下代码但产生了值错误:
writer=df1[df1['Model']==df2['Product']]
Would appreciate any help.将不胜感激任何帮助。
Try joining the DataFrames on the index using pandas.DataFrame.join
then exporting the result as a csv using pandas.DataFrame.to_csv
.尝试使用 pandas.DataFrame.join 将数据帧加入索引,然后使用pandas.DataFrame.join
将结果导出为pandas.DataFrame.to_csv
。
df1.join(df2)
df1.to_csv('./df2.csv')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.