【问题标题】:Select the specific column from csv and update the another csv从 csv 中选择特定列并更新另一个 csv
【发布时间】:2020-02-13 08:01:20
【问题描述】:

我有一个目录,其中包含许多带有 .csv 文件的文件夹,我需要从所有 .csv 中选择一个特定列并附加到另一个 result.csv 中

【问题讨论】:

  • 查找csvkit

标签: python shell csv parsing scripting


【解决方案1】:

您应该使用 os 库一一读取所有 csv 文件并读取/保留您想要的特定列,像这样

csv_file = pd.read_csv("csv_name_from_os.csv") 
column_val_list = csv_file.specific_column_name._ndarray_values

然后您可以使用

连接多个列
result = pd.concat([result, dat2], axis=1) 

最后你应该将框架保存为 csv 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 2016-06-07
    • 1970-01-01
    相关资源
    最近更新 更多