0

Suppose I have this dataframe:

                  date_group crypto     dollar
0  2023-05-24 21:00:00-03:00    BTC  -16147765
1  2023-05-24 21:30:00-03:00    BTC  -44579879
2  2023-05-24 21:30:00-03:00   USDC    8378950

I managed to get the data grouped in blocks of 30 mins, but I've been struggling to achieve the final bar chart that I'm seeking. Any guidance would be massively appreciated.

The bar chart is supposed to look like this:

Bar chart example

I hope the idea makes sense. I'm really eager to learn how to plot these properly. Even tried with chat GPT. I also looked at this page, but it wasn't very useful.

EDIT in reply to @Bill:

Image example

1 Answers1

0

Is this what you wanted?

import matplotlib.pyplot as plt

df_pivot = df.pivot(index="date_group", columns="crypto", values="dollar")
df_pivot.plot.bar(stacked=True)
plt.tight_layout()
plt.show()
print(df_pivot)
crypto                 BTC       USDC
date_group                           
21:00:00-03:00 -16147765.0        NaN
21:30:00-03:00 -44579879.0  8378950.0

stacked bar chart

Bill
  • 10,323
  • 10
  • 62
  • 85
  • You might also want to consider the [`pandas.Period`](https://pandas.pydata.org/docs/reference/api/pandas.Period.html) type. It's useful when you are working in regular time periods like your 3 hours. – Bill May 27 '23 at 00:58