pandas 将一个数据框附加到另一个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39301465/
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-09-14 01:57:18  来源:igfitidea点击:

Appending one data frame into another

pythonpandasdataframe

提问by arpit joshi

I want to bring three data frames into a single one .All data frames have a single column .

我想将三个数据框合并为一个。所有数据框都有一列。

org_city_id=p.DataFrame(training_data['origcity_id'])
pol_city_id=p.DataFrame(training_data['pol_city_id'])
pod_city_id=p.DataFrame(training_data['pod_city_id'])

All have 100 records in it so my goal is to bring them into a single data frame which will then contain 300 records .My below code is not working

全部都有 100 条记录,所以我的目标是将它们放入一个包含 300 条记录的数据框中。我下面的代码不起作用

org_city_id.append([pol_city_id,pod_city_id])

the total number of records in org_city_id is still 100 .

org_city_id 中的记录总数仍然是 100 。

Can someone please suggest .

有人可以建议。

采纳答案by Boud

Get a single column name for all your dataframes:

为所有数据框获取一个列名:

org_city_id.columns = pol_city_id.columns = pod_city_id.columns = 'Final Name'

Then concat them:

然后连接它们:

pd.concat([org_city_id,pol_city_id,pod_city_id])

回答by piRSquared

dfs = [org_city_id, pol_city_id, pod_city_id]
pd.concat([df.squeeze() for df in dfs], ignore_index=True)

回答by Harrison

You can use concatfrom Pandas documentation.

您可以使用Pandas 文档中的concat

Here is what you'll do:

您将执行以下操作:

pd.concat([org_city_id, pol_city_id, pod_city_id])

pd.concat([org_city_id, pol_city_id, pod_city_id])