我有一個DF刪除無細胞,如何從一個數據幀在python
contents values scoresBinned categories
0 Buy 484 (375, 500] Bin 4
1 Sell 429 (375, 500] Bin 4
2 Blanks 130 (125, 250] Bin 2
3 A 108 (0, 125] Bin 1
4 B 77 (0, 125] Bin 1
5 F 2 (0, 125] Bin 1
,因爲我需要爲賓我的頭,我做的DF,樞
filter_df1=df[["contents","categories"]]
pivot_df=filter_df1.pivot(columns="categories")
print(pivot_df)
contents
categories Bin 1 Bin 2 Bin 4
0 None None Buy
1 None None Sell
2 None Blanks None
3 A None None
4 B None None
5 F None None
我試過df.dropna (),但它會刪除整個行,
我期望df是,
Bin 1 Bin 2 Bin 4
A Blanks Buy
B Sell
F
你怎麼輸出你的數據幀? – WhatsThePoint
你想要的數據幀沒有意義。從數據框中刪除單個「單元格」是沒有意義的。你想要的輸出將數值放入它們以前不在的行中,即它完全忽略數據並返回一些毫無意義的東西。 –
我編輯了我的問題,請檢查 – pyd