Python 一次附加多个熊猫数据框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36526282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:59:36  来源:igfitidea点击:

Append multiple pandas data frames at once

pythonpandasappend

提问by user3664020

I am trying to find some way of appending multiple pandas data frames at once rather than appending them one by one using

我试图找到某种方式一次附加多个熊猫数据帧,而不是使用

df.append(df)

Let us say there are 5 pandas data frames t1, t2, t3, t4, t5. How do I append them at once? Something equivalent of

假设有 5 个 Pandas 数据框t1, t2, t3, t4, t5。我如何一次附加它们?相当于

df = rbind(t1,t2,t3,t4,t5)

采纳答案by tfv

Have you simply tried using a list as argument of append? Or am I missing anything?

您是否只是尝试使用列表作为 append 的参数?还是我错过了什么?

import numpy as np
import pandas as pd

dates = np.asarray(pd.date_range('1/1/2000', periods=8))
df1 = pd.DataFrame(np.random.randn(8, 4), index=dates, columns=['A', 'B', 'C', 'D'])
df2 = df1.copy()
df3 = df1.copy()
df = df1.append([df2, df3])

print df

回答by jezrael

I think you can use concat:

我认为你可以使用concat

print pd.concat([t1, t2, t3, t4, t5])

Maybe you can ignore_index:

也许你可以ignore_index

print pd.concat([t1, t2, t3, t4, t5], ignore_index=True)

More info in docs.

文档中的更多信息。