'Pandas: how to add each row of a column the value with each other

csv file with for each date the earning

In the image you see a csv file, I want to add for each date, in the example 01-01-2020, the earnings of that date witch eachother and also for the other date, so an example for 01-01-2020 is the total earnings 11.50. So i can use in bokeh on the x-axis the date and on the y-axis the total amount of that date. How can i achieve that?



Solution 1:[1]

You can use the groupby to obtain what you described

df('date')['earning'].sum()

Solution 2:[2]

Something like might work:

>>> date = ['01-01-2020', '01-01-2020', '02-01-2020', '02-02-2020','03-02-2020','03-02-2020']
>>> df = pd.DataFrame({'earning': earnings, 'date': date})
>>> df
   earning        date
0     10.0  01-01-2020
1      1.5  01-01-2020
2      6.4  02-01-2020
3      5.4  02-02-2020
4      7.8  03-02-2020
5      9.7  03-02-2020
>>> df.groupby(['date'])['earning'].sum()
date
01-01-2020    11.5
02-01-2020     6.4
02-02-2020     5.4
03-02-2020    17.5
Name: earning, dtype: float64

You could then use the plot function on the resulting dataframe from sum operation.

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 ArchAngelPwn
Solution 2 Sajan