0
    Model             Order_Date    Units_Sold
0   Blue Widget      2020-06-01     3
1   Green Widget     2020-06-04     4
2   Red Widget       2020-06-04     8 
3   Blue Widget      2020-06-02     3
4   Blue Widget      2020-06-03     5
5   Red Widget       2020-06-03     7
6   Green Widget     2020-06-04     3
7   Red Widget       2020-06-02     5
8   Green Widget     2020-06-01     7

Hey guys, So what I am trying to do is get the count of dates from the unique "order_dates" in Python. So this one is looking at 2020-06-01 to 2020-06-04, so count of 4. I want to be able to save this to a variable, thanks.

Nuvol
  • 11
  • 1

2 Answers2

1

Suppose your DataFrame is named df. Then try:

len(df['Order_Date'].unique())

The .unique() function can be used to get exactly 1 instance of each unique value from a pandas Series column. Then, you can just take the len of that array to get the number of unique values.

nathan.j.mcdougall
  • 475
  • 1
  • 6
  • 12
0

You can also use groupby like so:

count = df.groupby(by=['Model'], axis=0).count()
NotAName
  • 3,821
  • 2
  • 29
  • 44