我嘗試在堆疊溢位時搜索它,我得到了很多類似的標題,但問題并不完全相同(看起來非常不同)。此外,閱讀一些檔案(并非全部來自 Pandas),但找不到任何方法來做到這一點。
假設我有一個像這樣的資料框:

如何在 Pandas 中將其組合成一行?也就是說,我怎樣才能有一行的值:
0.000181 0.10139 0.009276 ... 0.0043778 ... 0.001094 0.004550 0.002879 ... 0.000435 0.003431 ...
從字面上看,這就是我試圖找到的全部。這些其他的事情是建議我做一個小組,或加入,或其他什么。
uj5u.com熱心網友回復:
rows=[] #initiate a list to store each row
for i in range(len(df)):
temp=df.loc[[i]] #extract each row
temp.columns=np.arange(i*len(temp.columns),(i 1)*len(temp.columns)) #rename column of each row
temp.reset_index(drop=True, inplace=True) #drop index
rows=rows [temp] #add it to the list of rows
output=pd.concat(rows,axis=1) #concat the list of rows by column
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/519749.html
標籤:Python熊猫数据科学
