asj177 asj177 - 3 months ago 9
Python Question

Appending one data frame into another

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

org_city_id.append([pol_city_id,pod_city_id])


the total number of records in org_city_id is still 100 .

Can someone please suggest .

Answer

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])