Using Python Slice
I'd like to remove the header from a csv datafile using the slide command. I need to do this because Python's 'open' command does not accept other header stripped commands like 'Header = False' or 'skiprows'. I don't understand how to use slice to remove a complete row and leave the rest of the file alone.
The dataset is from the diamonds training set. Here are the first two rows, followed by the rest of the function I'm working on:
carat,cut,color,clarity,depth,table,price
0.23,Ideal,E,SI2,61.5,55,326
---------
def loadDataSet():
dataMat = []; labelMat = []
fr = open('diamonds.csv')
fr.skip_header = 2
for line in fr.readlines():
lineArr = line.strip().split()
dataMat.append([1.0, float(lineArr[0]), float(lineArr[1])])
labelMat.append(int(lineArr[2]))
return dataMat,labelMat
loadDataSet()
#use python3 IDLE
#create a csv file using notepad with extension .csv on e:\ drive
#file name is mydata.csv
#save on e:\ drive
#so the path is "e:\\mydata.csv"

#code below is editable, but
to maintain indentation please use image of code
f=open("e:\\mydata.csv")
list1=f.readlines()
print("Original Data")
for x in list1:
print(x)
f.close()
list2=[]
list3=[]
def loadDataset():
f=open("e:\\mydata.csv")
list1=f.readlines()
list2=list1[1:]#slicing
return list2
print("After removing first row")
print()
list3=loadDataset()
for x in list3:
print(x)
Using Python Slice I'd like to remove the header from a csv datafile using the slide...