Issue
I get a value error when I want to load the following data set. I skipped the first line because it says "don't take titles - first line" in some sources. But again it gave an error on another line.
from numpy import loadtxt
path = r"C:\Users\emre.yildirim\Desktop\Dominos_Stock_Data.csv"
datapath = open(path,'r')
data = loadtxt(datapath,delimiter=",")
ValueError: could not convert string to float: 'Date'
from numpy import loadtxt
path = r"C:\Users\emre.yildirim\Desktop\Dominos_Stock_Data.csv"
datapath = open(path,'r')
data = loadtxt(datapath,delimiter=",",skiprows=1)
ValueError: could not convert string to float: '2019-10-16'
Solution
Try genfromtxt
instead of loadtxt
And also, as the header has text string, numpy substitutes with nan
(i guess) as the dtype
is float
by default
So try skip_header=1
along with it in the genfromtxt
Code:
from numpy import genfromtxt
path = r"C:\Users\emre.yildirim\Desktop\Dominos_Stock_Data.csv"
datapath = open(path,'r')
data = genfromtxt(datapath, delimiter="," ,skip_header=1)
Outputs everything excluding the header
Tell me if its not working...
Answered By - Ghost Ops
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.