如何跳过CSV文件的列 [英] How to Skip Columns of CSV file
问题描述
我正在尝试将数据从CSV文件中的某些字段上传到已经存在的表中.
I am trying to upload data from certain fields in a CSV file to an already existing table.
据我了解,实现此目的的方法是创建一个新表,然后将新创建的表的相关列附加到主表的相应列中.
From my understanding, the way to do this is to create a new table and then append the relevant columns of the newly created table to the corresponding columns of the main table.
如何准确地将某些数据列从一个表追加到另一个表? 像是什么命令?
How exactly do I append certain columns of data from one table to another? As in, what specific commands?
我正在使用bigquery api和python-client-library.
I am using the bigquery api and the python-client-library.
推荐答案
您可以为此使用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
You can use pandas library for that.
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文件的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!