我手動構建了資料框(df1,下面的代碼)。對于這個資料框 df1,我怎樣才能洗掉第一列(行號)?提前謝謝了
df1 = pd.DataFrame({"date": ['2021-3-22', '2021-4-7', '2021-4-18', '2021-5-12'],
"x": [3, 3, 3, 0 ]})
Output:
date x
0 2021-3-22 3
1 2021-4-7 3
2 2021-4-18 3
3 2021-5-12 0
uj5u.com熱心網友回復:
簡單的使用set_index方法。
import pandas as pd
df1 = pd.DataFrame({"date": ['2021-3-22', '2021-4-7', '2021-4-18', '2021-5-12'],
"x": [3, 3, 3, 0 ]})
df1.set_index('date', inplace=True)
uj5u.com熱心網友回復:
默認資料框表示將默認顯示索引號。如果您想查看沒有索引的資料框,可以使用.to_stringwith 方法index=False。
>>> df1
date x
0 2021-3-22 3
1 2021-4-7 3
2 2021-4-18 3
3 2021-5-12 0
>>>
>>> print(df1.to_string(index=False))
date x
2021-3-22 3
2021-4-7 3
2021-4-18 3
2021-5-12 0
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/524426.html
標籤:Python熊猫数据框
上一篇:計數值排除重復ID
