I have a csv file with 3 columns:
- Timestamp
- Measured response time
- Model name
Timestamp,ResponseTime,Model16-07-2021 17:59:22,1.421802,trained_sm_9516-07-2021 17:59:23,1.414357,trained_sm_9516-07-2021 17:59:25,1.623063,trained_sm_9516-07-2021 17:59:27,1.401964,trained_md_9616-07-2021 17:59:28,1.4,trained_md_9616-07-2021 17:59:29,1.396638,trained_md_9616-07-2021 17:59:31,1.601539,trained_lg_9516-07-2021 17:59:33,1.205376,trained_lg_9516-07-2021 17:59:34,1.411902,trained_lg_95I want to visualize the response time in a multiple line chart with 3 lines, one for each model.My code looks like this:
df = pd.read_csv(r'D:\temp\times.csv')#pd.to_datetime(df['Timestamp'],errors='ignore') sm = df.ResponseTime[df["Model"] == 'trained_sm_95']md = df.ResponseTime[df["Model"] == 'trained_md_96']lg = df.ResponseTime[df["Model"] == 'trained_lg_95']x = df.Timestampplt.rcParams["font.family"] = "Times New Roman"plt.scatter(x, y)plt.plot( 'x', 'sm', data=df)plt.plot( 'x', 'md', data=df)plt.plot( 'x', 'lg', data=df)plt.legend()plt.show()The code is currently breaking at this line:
plt.plot('x', 'lg', data=df)with this error:
ValueError: Unrecognized character
lin format string
I don't see what's wrong with the code.
How can I load and visualize the data as described above?
1 Answer1
Okay, there are multiple mistakes here... first, to plot your data, you have to pass the variables into the function parameters, whereas you are passing strings that are the same as the variable names... so it should look like this.
plt.plot(x, sm)plt.plot(x, md)plt.plot(x, lg)Your syntax would be valid only ifdfwould contain 'x', 'lg', 'md' or 'sm', which could be accessed through eg.
df['x']If it does, then, and only then, you could use the syntax you were using. Look here for more detailPlot Don't be afraid to read the docs :)
1 Comment
Explore related questions
See similar questions with these tags.


