import pandas as pdpd.__version__df = pd.read_csv('myfile.csv', usecols=[0,3,4,5,9])print (df)我只想從 csv 文件返回這些特定列并將其寫入新的 csv 文件?我怎樣才能做到這一點(diǎn)到目前為止我可以讀取數(shù)據(jù)!但不知道怎么寫絕對(duì)的 Python 初學(xué)者警告
1 回答

慕后森
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
根據(jù)您的輸入,我假設(shè)您正在嘗試實(shí)現(xiàn)類似的目標(biāo)?
#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)
添加回答
舉報(bào)
0/150
提交
取消