I am trying to plot 2 columns from a csv file. Each column contains list of values. How can I plot those columns. The columns are read as strings and unable to identify the "[" character.
Here's a snippet of my csv. I want to plot column1 versus column2 for all Names(A,B,C)
Name Column1 column2 Column3
A [0.1,0.2,0.3] [0.1,0.2,0.3] 0.2
B [0.9,0.7,0.3] [0.1,0.8,0.3] 0.2
C [0.1,0.2,0.6] [0.1,0.2,0.3] 0.2
I tried to use the following code
r = pd.read_csv('L.csv')
plt.plot(r.loc[i]['Column1'].astype(float),
r.loc[i]['Column2'].astype(float),
linestyle="--",
label="{}, Led={:.3f}".format(i, r.loc[i]['Column3']))
CodePudding user response:
You can use ast.literal_eval()
function to convert string types to types present inside the string: