下面將對DataFrame的基本操作進行梳理和介紹:(下文中用df代指DataFrame格式)
方法1:直接生成df
方法2:字典轉化為df
方法3:讀取txt/excel文件時,輸出的就是df格式
方法4:從矩陣A轉化為df
註:pd.DataFrame和pd.Series是兩個不同的函數
取單行後是壹個Series,Series有index而無columns
'Series' object has no attribute 'columns'
去除nan值:
1pandas dataframe刪除壹行或壹列:drop函數 /songyunli1111/article/details/79306639
註意:
df.append 生成了新的對象
list.append 直接修改原對象
如果要合並多個Dataframe,可以用list把幾個Dataframe裝起來,然後使用concat轉化為壹個新的Dataframe
拆分
使用sum默認對每列求和,sum(1)為對每行求和
兩個series可以直接進行加減乘除計算
pd.set_option('display.width', 200) # 橫向最多顯示多少個字符, 壹般80不適合橫向的屏幕,平時多用200.
pd.set_option('display.max_columns', 12)
pd.set_option('display.max_rows', 10) # 顯示的最大行數和列數
pd.set_option('colheader_justify', 'left') 顯示的單元格內容靠左邊還是右邊
1 DataFrame多重索引 /kylinxjd/article/details/98621546
1Python在Dataframe中新添加壹列 /zx1245773445/article/details/99445332
2插入:pandas-DataFrame列移動 /sinat_41701878/article/details/80945861