Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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.

>Solution :

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

Similar question has been answered here.

Pandas documentation for this function: pandas.concat

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading