'How to count the number of occurence daily for each element in a dataframe

Being working with a KPIs dataframe where I've a set of KPIs for different element and each KPI having a value hourly, e.g below.

The CSV text used to create the dataframe cand be found here : https://textsaver.flap.tv/lists/4ta4

Main Dataframe :

Main Dataframe

filtering by an element :

One element example

Filtering by another element :

Second element example

What I want to do actually is to have the Daily Occurence for each element on it's own, I've tried with the Resampling functions but the result is global to the whole Dataframe and not Cell column wise.

Result when using **Resample" function :

Resample function result

While below is the desired result :

Desired result

Any suggestions ?



Solution 1:[1]

IUUC, you can try groupby date and Cell column then compute group sizes.

df['Time'] = pd.to_datetime(df['Time'])
out = df.groupby([df['Time'].dt.date, 'Cell']).size().reset_index(name='Count')
print(out)

          Time        Cell  Count
0   2022-05-08   LAL0005_H      7
1   2022-05-08  LAL0005_H2     11
2   2022-05-08  LAL0005_I2      1
3   2022-05-08  LAL0005_Y2      4
4   2022-05-09   LAL0005_H      2
5   2022-05-09  LAL0005_H2      7
6   2022-05-09  LAL0005_Y2      1
7   2022-05-10   LAL0005_H      1
8   2022-05-10  LAL0005_H2      9
9   2022-05-11   LAL0005_H      1
10  2022-05-11  LAL0005_H2      8
11  2022-05-12   LAL0005_H      2
12  2022-05-12  LAL0005_H2      7
13  2022-05-13   LAL0005_H      4
14  2022-05-13  LAL0005_H2     10
15  2022-05-14   LAL0005_H      8
16  2022-05-14  LAL0005_H2     12

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ynjxsjmh