0
votes

I have a csv file with measuring points every 100 seconds. 5 different measurements have been made. I am looking for a simple solution how to create a line plot with the average value for each measuring point with the min, max values as a bar with Python. The CSV file looks like this:

0,0.000622,0.000027,0.000033,0.000149,0.000170 100,0.014208,0.017168,0.017271,0.015541,0.027972 200,0.042873,0.067629,0.035837,0.033160,0.018006 300,0.030700,0.018563,0.016640,0.020294,0.020338 400,0.018906,0.016507,0.015445,0.018734,0.017593 500,0.027344,0.045668,0.015214,0.016045,0.015520 600,0.021233,0.098135,0.016511,0.015892,0.018342

First column is in seconds.

Maybe someone can help me with a quick idea.

thanks in advance

--------------------added

What i have so far:

import pandas as pd

input_df = pd.read_csv(input.csv")
input_df['max_value'] = input_df.iloc[:,1:6].max(axis=1)
input_df['min_value'] = input_df.iloc[:,1:6].min(axis=1)
input_df['avg_value'] = input_df.iloc[:,1:6].mean(axis=1)

input_df.plot(x=input_df["0"], y='avg_value')

How can i add error bars (min_value,max_value)

1
What have you tried so far? Check out pandas, the docs are awesome pandas.pydata.orgBrayden
It is easy for us to start with some provided code rather than starting to write a code for you from scratch.Sheldore
input_df.plot(x=input_df["0"], y='avg_value', yerr=['min_value', 'max_value']) This line does not work like i wished.MSO

1 Answers

1
votes

You can use matplotlib. For your problem:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data=np.array([ [0,0.000622,0.000027,0.000033,0.000149,0.000170],
            [100,0.014208,0.017168,0.017271,0.015541,0.027972],
            [200,0.042873,0.067629,0.035837,0.033160,0.018006],
            [300,0.030700,0.018563,0.016640,0.020294,0.020338],
            [400,0.018906,0.016507,0.015445,0.018734,0.017593],
            [500,0.027344,0.045668,0.015214,0.016045,0.015520],
            [600,0.021233,0.098135,0.016511,0.015892,0.018342] ])
mean = np.mean(data[:,1:], axis=1)
min = np.min(data[:,1:], axis=1)
max = np.max(data[:,1:], axis=1)
errs = np.concatenate((mean.reshape(1,-1)-min.reshape(1,-1), max.reshape(1,-1)- 
mean.reshape(1,-1)),axis=0)

plt.figure()
plt.errorbar(data[:,0], mean, yerr=errs)
plt.show()