Home > Mobile >  Select specific column from multiple dataframe to combine into one dataframe pandas
Select specific column from multiple dataframe to combine into one dataframe pandas

Time:07-08

I want to select specific columns from multiple dataframes and combine them into one dataframe, how can I accomplish this?

df1

   count    grade
0   3        0
1   5        100
2   4        50.5
3   10       80.10


df2

    books   saving
0   4        10
1   5        9000
2   8        70
3   10       500

How can I select the saving column from df2 and combine with grade column from df1 to form a separate pandas dataframe that looks like the below.

    grade     saving
0   0           10
1   100        9000
2   50.5        70
3   80.10       500


I tried

df = pd.DataFrame([df1['grade'],df2['saving']])
print(df)

but the outcome is not what I wanted.

CodePudding user response:

df = pd.concat([df1['grade'], df2['saving']], axis=1)

Similar question has been answered here.

Pandas documentation for this function: pandas.concat

  • Related