How can I turn the Timestamp column into the values ​of the X axis in the plot

Viewed 23
p = df[df['Name'].str.contains(NER, na = True)]
p['Result'] = p['Result'].astype('float')    
p.groupby(["Name"])["Result"].plot(legend=True ,figsize=(15,10))
plt.legend(loc ='upper right')
plt.savefig('figure.png')
plt.close()

How can I turn the Timestamp column into the values ​​of the X axis in the plot I tried: p.set_index("Timestamp", inplace=True) But the x-axis starts from 00:00:00 and not from the time of the first index (09:34:54).

p after the line: p['Result'] = p['Result'].astype('float')

       Timestamp         Name  Result
7       09:34:54  TRX0_NER_M0     1.0
8       09:34:54  TRX0_NER_M1     1.0
9       09:34:54  TRX1_NER_M0     1.0
10      09:34:54  TRX1_NER_M1     1.0
11      09:34:54  TRX2_NER_M0     1.0
...          ...          ...     ...
401465  09:47:00  TRX1_NER_M1     1.0
401466  09:47:00  TRX2_NER_M0     1.0
401467  09:47:00  TRX2_NER_M1     1.0
401468  09:47:00  TRX3_NER_M0     1.0
401469  09:47:01  TRX3_NER_M1     1.0

[38341 rows x 3 columns]
1 Answers

i can see you are using time in format hh:mm:ss you can use this code to get the number of seconds which can be used for x axis. I created a function which u can use.

def get_seconds(timestamp):
   time=list(map(int,timestamp.split(":")))
   h=time[0]
   m=time[1]
   s=time[2]
   total=h*3600+m*60+s
   return total
print(get_seconds("09:34:54"))
Related