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

how to compare columns in data frame

I’m trying to visually compare two columns in a data frame and it either makes a weird table with ‘frequency’ instead of one of the columns

I tried these options:

ct1=pd.crosstab(df['releaseyear'],df['score'],normalize=True)
ct1.plot()

df.plot( x='releaseyear', y='score', kind='hist')

and also a scatter plot which get the x and y right but I don’t know how normalize it so it will only show the average of each year and not all the data

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

plt.scatter(df['releaseyear'], df['score'])
plt.show()

>Solution :

There is no proper data which can be used to reproduce the dataframe or clue about how dataframe looks.

This answer is according to what i understood if data is like this

   year score
   2001 20
   2001 18
   2002 12
   2002 16

then first use groupby and group data according to year and apply required aggregate function.

df=df.groupby('year').mean().reset_index()

output

   year  score
0  2001   19.0
1  2002   14.0

you can then plot the data accordingly.

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