Reputation: 1
Although there are many topics on this error I cant find any that have a solution that will help me. I have headers labelled bottom, left, and right in my .csv Excel file, when I try to plot them I get a could not convert string to text error due to these headers. How could I solve this?
import matplotlib.pyplot as plt
import numpy as np
# Read the input data only once
Bottom, Left, Right = np.loadtxt ("C:Data 2.csv", delimiter=",", skiprows=1, unpack=True)
# Plot in the first axis
ax1.plot(Bottom, Left, label='Pressure/area', color='b')
plt.show()
This is what the file looks like:
Upvotes: 0
Views: 337
Reputation:
one of the other approches that you can take is to read the csv file throught pandas using pd.read_csv. This will help you solve your problem. for example:- if my filepath is 'example/path/pathtofile'
import pandas as pd
filepath = 'example/path/pathtofile'
data = pd.read_csv(filepath)
Upvotes: 1