數據清洗

import xlrd
import pandas as pd
import numpy as np

data = xlrd.open_workbook('D:\\Data\\basket.xlsx')



table= data.sheets()[0]
nrows = table.nrows
ncols=table.ncols
j=2
for i in nrows:
	 if table.cell(i,0).value != table.cell(i+1,0).value:
	 	 li(i,j)= table.cell(i,0)
	 	 li[i,]
	 	 j=j+1
	 else :
	 	j=2
	 	i = i+1


df=pd.read_excel('D:\\Data\\basket.xlsx')
df.iloc[1,1]---取某個值
st=np.empty([330000,20],dtype=str)
st=np.empty([330000,20],dtype=unicode)
n = 330000
i=1
j=2
z=1
st[0,0]=df.iloc[0,0]
st[0,1]=df.iloc[0,1]
for i in n:
	if df.iloc(i,0) != df.iloc(i-1,0):
		st[i,0]=df.iloc(i,0)
		st[i,1]=df.iloc(i,1)
		i=i+1
		j=2
		z=1
	else:
		st[i-z,j]=st[i,1]
		j=j+1
		z=z+1


df=pd.read_excel('D:\\Data\\basket.xlsx')
df.iloc[1,1]---取某個值
st=np.empty([330000,20],dtype=str)
st=np.empty([330000,100],dtype=int)
n = 330000
i=1
j=2
z=1
st[0,0]=i-1
st[0,1]=df.iloc[0,1]


for i in range(1, n):
	if df.iloc[i,0] != df.iloc[i-1,0]:
		st[i,0]=i
		st[i,1]=df.iloc[i,1]
		i=i+1
		j=2
		z=1
	else:
		st[i-z,j]=st[i,1]
		j=j+1
		z=z+1




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章