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

'DataFrame' object has no attribute 'value_counts' in pandas 0.25

I am using
pandas==0.25.0
django-pandas==0.6.1

And I am using value_counts() to group for unique valor in two columns:

 charges_mean_provinces = whatever.objects.filter(whatever = whatever).values('origin_province','destination_province')

 df_charges_mean = pd.DataFrame(charges_mean_provinces)
 df_charges_mean = df_charges_mean.value_counts().to_frame('cantidad').reset_index()

In local (development) it work correctly. But in production (I use Heroku), it return this error.

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

  'DataFrame' object has no attribute 'value_counts'

Is there other way to group unique valor from two columns without use value_counts? Considering that I can not change my Pandas version in Heroku.

Anyway, value_counts is in pandas 0.25 documentation, so, I do not understand the error.

>Solution :

What version of Pandas are you using? Initially, value_counts is a method for series, rather than dataframes. You can call value_counts on a specific column, but not the frame itself.

After 1.10, that was updated and now value_counts is also a dataframe method. I recall seeing posts previously on here regarding this error before pandas was updated.

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