How can I add a column from one dataframe to another dataframe?

if you want to add the column at the end, you can use

df1['columename']= df2['existing_colume_name']

and after that apply

df1.column_name = df1.column_name.astype(float)

This worked for me !


correct answer:

df1['column_name'] = df2['column_name'].values

the thing is you need to pass an object of a certain type for it to work correctly. List or array are preferable.


The data types in df1 are all integer and the data type for df2 is string. Whenever I merge/concat/join, I get NaN instead of the right data.

If you want to add the df2 value to the df1 value, you need to convert the df2 field to an integer.

df2['FieldName'] = df2['FieldName'].astype(int)