[英]Combining three dataframes horizontally in pandas
I have three data frames each of shape 100*100 how i combine them horizontally to a new data frame of shape 300*100? 我有三个形状为100 * 100的数据框,如何将它们水平组合到形状为300 * 100的新数据框? I tried using these commands: 我尝试使用以下命令:
result = df1.combine_first(df2)
result = pd.concat([df1, df2], axis=1, join_axes=[df1.index])
result = df1.append(df2, ignore_index=True)
But non gave the desired result of a data frame of shape 300*100. 但是non给出了形状为300 * 100的数据帧的预期结果。 How i can do that? 我该怎么做?
If you want to combine 3 100 x 100
df
s to get an output of 300 x 100
, that implies you want to stack them vertically. 如果要组合3 100 x 100
df
s以获得300 x 100
的输出,则意味着您要垂直堆叠它们。 So, try axis=0
. 因此,尝试axis=0
。
It might be necessary to rename your columns first, so you could do that in a loop. 可能有必要先重命名您的列,以便可以循环执行。
df_list = [df1, df2, df3]
for d in df_list[1:]:
d.columns = df_list[0].columns
df = pd.concat(df_list, axis=0, ignore_index=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.