Dametre Thunberg
Dametre Thunberg

Reputation: 1

Could not convert string to float -headers

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:

 can't find a way to link the exact file but it's really only a problem with the headers

Upvotes: 0

Views: 337

Answers (1)

user9846785
user9846785

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

Related Questions