0

My raw dataframe is like this :

df = pd.read_csv('sample.csv')
df
          time               keys   values
0   2022-12-07_10:04:12 A   815.5
1   2022-12-07_10:04:12 B   1987.0
2   2022-12-07_10:04:13 A   819.0
3   2022-12-07_10:04:13 B   1987.0
4   2022-12-07_10:04:14 A   822.5
5   2022-12-07_10:04:14 B   1985.0
6   2022-12-07_10:04:15 A   825.5
7   2022-12-07_10:04:15 C   100.5

I want to plot a chart to observe A and B how to vary based on time.

I think I need to get a dataframe like this:

time                    A-values    B-values 
2022-12-07_10:04:12     815.5        1987.0
2022-12-07_10:04:13     819.0        1987.0
2022-12-07_10:04:14     822.5        1985.0
2022-12-07_10:04:15     825.0        NaN

I try:

ab = df.loc[df['keys'].str.contains('A|B')]
ab.groupby('time')

And I don't know what I should do next...... there must be a way, Thanks you so much! (Sorry for my poor English)

ryan-wu
  • 1
  • 1

0 Answers0