3 回答

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
您希望發(fā)生這種情況的情況尚不清楚,但一種好的通用方法是
df1 = pd.read_csv(...) # Read the file.
df2 = pd.DataFrame(...) # Make a DataFrame of the new entries you want to add.
df = pd.concat([df1, df2]) # Concatenate the two.
df.to_csv(...) # Write the file to the original directory.

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
df.iloc[location].T.to_csv('filename.csv',mode='a',index=False,header=False)

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超11個(gè)贊
df.iloc[location]
可以給你Series
哪些不同的待遇DataFrame
您必須將其轉(zhuǎn)換為DataFrame
但使用列表Series
來獲取行而不是列中的數(shù)據(jù)
df = pd.DataFrame( [df.iloc[location]] )
然后保存到?jīng)]有標(biāo)題的csv
df.to_csv(path, mode='a', header=None)
編輯:您也可以轉(zhuǎn)換Series
為DataFrame
使用.to_frame()
,然后使用.T
將列轉(zhuǎn)置為行
df = df.iloc[location].to_frame().T
添加回答
舉報(bào)