【问题标题】:How to Skip Columns of CSV file如何跳过 CSV 文件的列
【发布时间】:2017-10-03 13:57:01
【问题描述】:

我正在尝试将 CSV 文件中某些字段的数据上传到现有表中。

据我了解,这样做的方法是创建一个新表,然后将新创建的表的相关列附加到主表的相应列中。

我究竟如何将某些数据列从一个表附加到另一个表? 如,具体的命令是什么?

我正在使用 bigquery api 和 python-client-library。

【问题讨论】:

    标签: python csv google-api google-bigquery google-python-api


    【解决方案1】:

    您可以为此使用 pandas 库。 import pandas as pd data = pd.read_csv('input_data.csv') useful_columns = [col1, col2, ... ] # List the columns you need data[useful_columns].to_csv('result_data.csv', index=False) # index=False is to prevent creating extra column

    【讨论】:

    • 这行得通,只是新 CSV 文件中的每个字段都包含原始文件中其右侧字段的值。有没有解决这个问题的内置参数?
    • 是的,有!我将index_col=False 传递给函数read_csv() 就成功了
    猜你喜欢
    • 2015-09-18
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 2015-03-07
    • 2020-02-22
    • 1970-01-01
    相关资源
    最近更新 更多