放假看书有一些想法,写一下。
a.append(b,ignore_index=True),追加,index顺序增加
pandas.concat([a,b]) a,b合并,index不变
import pandas
from pandas import DataFrame
a = DataFrame({'math':[85,50,65],'chinese':[90,85,60]})
b = DataFrame({'math':[80,90],'chinese':[85,60]})
c = b.append(a,ignore_index=True)
a =
chinese math
0 90 85
1 85 50
2 60 65
b =
chinese math
0 85 80
1 60 90
c =
chinese math
0 85 80
1 60 90
2 90 85
3 85 50
4 60 65
import pandas
from pandas import DataFrame
a = DataFrame({'math':[85,50,65],'chinese':[90,85,60]})
b = DataFrame({'math':[80,90],'chinese':[85,60]})
c = pandas.concat([a,b])`在这里插入代码片`
c
chinese math
0 90 85
1 85 50
2 60 65
0 85 80
1 60 90
注意二者index的区别
仅当使用append时,ignore_index= True
import pandas
from pandas import DataFrame
a = DataFrame({'math':[85,50,65],'chinese':[90,85,60]})
b = DataFrame({'math':[80,90],'chinese':[85,60]})
b.append(a)
chinese math
0 85 80
1 60 90
0 90 85
1 85 50
2 60 65
append默认情况下ignore_index= False