1.在行或列追加(相当于append的功能)
1.1使用.loc追加一行
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import pandas as pd df = pd.read_csv('20190708.csv') dfa = df.iloc[[0,1,2,3],[1,2,3,4]] dfa.index = ['a','b','c','d'] print(dfa) ##追加一行 dfa.loc['e',:] = dfa.loc['d',:] print(dfa)
1.2使用.loc追加一列
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import pandas as pd import numpy as np df = pd.read_csv('20190708.csv') dfa = df.iloc[[0,1,2,3],[1,2,3,4]] dfa.index = ['a','b','c','d'] print(dfa) ##追加一列 dfa.loc[:,'add_column'] = 6 print(dfa)
1.3通过[]追加一列
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import pandas as pd import numpy as np df = pd.read_csv('20190708.csv') dfa = df.iloc[[0,1,2,3],[1,2,3,4]] dfa.index = ['a','b','c','d'] print(dfa) ##追加一列 dfa['add_column'] = 6 print(dfa)