简体   繁体   中英

Select specific column from multiple dataframe to combine into one dataframe pandas

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.

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

Similar question has been answered here .

Pandas documentation for this function:pandas.concat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM