第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何將數(shù)據(jù)框?qū)С龅浆F(xiàn)有的格式化 csv 文件?

如何將數(shù)據(jù)框?qū)С龅浆F(xiàn)有的格式化 csv 文件?

素胚勾勒不出你 2022-05-11 16:41:04
我正在嘗試將數(shù)據(jù)框?qū)С龅浆F(xiàn)有的格式化 csv 文件,但數(shù)據(jù)框繼續(xù)以垂直形式附加,以及應(yīng)該水平的附加標(biāo)題。A B C D E F1 2 3 4 5 6   #=-> This is the format I have in my exisiting csv fileA B C D E F1 2 3 4 5 6x x x x x x   #-> This is how I want to do itA B C D E F1 2 3 4 5 6A 1B 2C 3 D 4  #-> This is what's currently happening任何幫助將非常感激。謝謝!df.iloc[location].to_csv(path,mode='a')這是我一直在嘗試的代碼。
查看完整描述

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.


查看完整回答
反對 回復(fù) 2022-05-11
?
BIG陽

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

df.iloc[location].T.to_csv('filename.csv',mode='a',index=False,header=False)



查看完整回答
反對 回復(fù) 2022-05-11
?
繁星淼淼

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)換SeriesDataFrame使用.to_frame(),然后使用.T將列轉(zhuǎn)置為行

df = df.iloc[location].to_frame().T


查看完整回答
反對 回復(fù) 2022-05-11
  • 3 回答
  • 0 關(guān)注
  • 247 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號