Simple plotting from txt file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Simple plotting from txt file (/thread-29194.html) |
Simple plotting from txt file - Laplace12 - Aug-22-2020 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? RE: Simple plotting from txt file - deanhystad - Aug-22-2020 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.
RE: Simple plotting from txt file - Laplace12 - Aug-23-2020 Thanks, I found the error: the first column(header) didn't include numbers so division couldn't be performed. |