import pandas as pd
pd.__version__
df = pd.read_csv('myfile.csv', usecols=[0,3,4,5,9])
print (df)
我只想从我的csv文件中返回这些特定的列并将其写入新的csv文件中?
我该怎么做
到目前为止,我可以读取数据!但不确定如何写
绝对PYTHON初学者警报
答案 0 :(得分:1)
根据您的输入,我认为您正在尝试实现这样的目标?
#import library
import pandas as pd
pd.__version__
# read the csv with all columns
df = pd.read_csv('myfile.csv')
print (df)
# create csv with filtered columns
filter_cols = ["0","3","4","5","9"]
df.to_csv('output.csv', columns = filter_cols)