我想将三个数据框合并为一个。所有数据框都有一列。
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'])
所有内容都有100条记录,所以我的目标是将它们放入一个数据框中,然后包含300条记录。我的下面的代码不能正常工作
org_city_id.append([pol_city_id,pod_city_id])
org_city_id中的记录总数仍为100。
有人可以建议。
答案 0 :(得分:2)
dfs = [org_city_id, pol_city_id, pod_city_id]
pd.concat([df.squeeze() for df in dfs], ignore_index=True)
答案 1 :(得分:1)
获取所有数据框的单个列名称:
org_city_id.columns = pol_city_id.columns = pod_city_id.columns = 'Final Name'
然后结识他们:
pd.concat([org_city_id,pol_city_id,pod_city_id])
答案 2 :(得分:0)