0

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.

  '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.

Miguel Herreros Cejas
  • 664
  • 1
  • 12
  • 28
  • 3
    Pandas.Series has `value_counts` for a long time. But Pandas.DataFrame just has it quite recently. – Quang Hoang Jan 13 '22 at 15:10
  • 2
    Does this answer your question? [AttributeError: 'DataFrame' object has no attribute](https://stackoverflow.com/questions/19392226/attributeerror-dataframe-object-has-no-attribute) – BigBen Jan 13 '22 at 15:11

1 Answers1

2

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.

rob0tst0p
  • 136
  • 9