1

I have a csv file with 3 columns:

  1. Timestamp
  2. Measured response time
  3. 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_95

I 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 characterl in format string

I don't see what's wrong with the code.

How can I load and visualize the data as described above?

tdy's user avatar
tdy
42.1k42 gold badges124 silver badges125 bronze badges
askedJul 16, 2021 at 20:55
Malte's user avatar

1 Answer1

1

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 :)

answeredJul 16, 2021 at 21:11
Petr Synek's user avatar
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the quick response. I adapted it now like this to make it working: plt.plot( df.Timestamp[df["Model"] == 'trained_sm_95'], df.ResponseTime[df["Model"] == 'trained_sm_95']) plt.plot( df.Timestamp[df["Model"] == 'trained_md_96'], df.ResponseTime[df["Model"] == 'trained_md_96']) plt.plot( df.Timestamp[df["Model"] == 'trained_lg_95'], df.ResponseTime[df["Model"] == 'trained_lg_95'])

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.