Python Forum

Full Version: Simple plotting from txt file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a very simple code to plot. The data file consists of seven columns with values (not integers), and I wish to plot their division. This is the code:

import pandas as pd
data = pd.read_csv('Co_foil_2.data',sep='\s+',header=None)
data = pd.DataFrame(data)

import matplotlib.pyplot as plt
y = data[0]
a = (data[1]/data[2])
b = (data[2]/data[2])
c = (data[3]/data[2])
d = (data[4]/data[2])
e = (data[5]/data[2])
f = (data[6]/data[2])

plt.plot(a, y,'r--')
plt.plot(b, y,'b--')
plt.plot(c, y,'g--')
plt.plot(d, y,'y--')
plt.plot(e, y,'m--')
plt.plot(f, y,'k--')
plt.legend()
plt.show()
However, this returns an error:

TypeError: unsupported operand type(s) for /: 'str' and 'str'
From what I understand, the columns can't be divided for some reason; am I simply using a wrong command, or is there something more prominently wrong in the code?
After you read_csv, what is in data? After you convert to DataFrame what is in data? If you type print(data[0], type(data[0])) what does it say? Something is preventing your data from being interpreted as numbers. Find out where that is happening and why.
Thanks, I found the error: the first column(header) didn't include numbers so division couldn't be performed.