Skip to content

Instantly share code, notes, and snippets.

@Cheers3985
Last active November 15, 2022 14:26
Show Gist options
  • Save Cheers3985/c98ee7ee14123b3445216f57627ca40b to your computer and use it in GitHub Desktop.
Save Cheers3985/c98ee7ee14123b3445216f57627ca40b to your computer and use it in GitHub Desktop.
#pandas.concat #pandas #python
# pandas.concat 实现竖向的拼接
import pandas as pd
df1=pd.DataFrame([10,12,13])
df2=pd.DataFrame([22,33,44,55])
df3=pd.DataFrame([90,94])
pd.concat([df1,df2,df3],ignore_index=True) # 纵向组合,注意此时没有设定列名。此时拼接只有一列
# --------concat 多列进行拼接---------
import pandas as pd
df1=pd.DataFrame([10,12,13],columns=['1'])
df2=pd.DataFrame([22,33,44,55],columns=['2'])
df3=pd.DataFrame([90,94],columns=['3'])
df = pd.concat([df1,df2,df3],ignore_index=True,)
df
# 此时按照有3列,结果如下
1 2 3
0 10.0 NaN NaN
1 12.0 NaN NaN
2 13.0 NaN NaN
3 NaN 22.0 NaN
4 NaN 33.0 NaN
5 NaN 44.0 NaN
6 NaN 55.0 NaN
7 NaN NaN 90.0
8 NaN NaN 94.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment