import pandas as pd from pandas import Series,DataFrame project_name='017' df1 = pd.read_excel('E:/%s.xls'%project_name,encoding = "GBK") #encoding = "GBK",中文编码格式 #文件过大,逐块迭代 chuncker=pd.read_csv('E:/basic.csv',chunksize=1000,encoding="GBK") df3=DataFrame() for piece in chuncker: df3=df3.append(piece) # print(df3) # print("___") print(len(df3)) # break df3=df3.reindex() print(len(df3)) #写入csv df3.to_csv('E:/%s.csv'%s) #不用pandas就比较复杂 data = open('E:/basic.csv',encoding='gbk',errors='ignore') print(type(data)) #print(type(data.read())) #df=data.read() #kk=data.readline(9) list1=[] for i in data.readlines(): list1.append(i) # print(dd) print(list1[0]) list2=[] for i in range(len(list1)): list2.append(list1[i].split(',')) print(list1[0].split(',')[0]) #print(list2) df_list=DataFrame() for i in range(1,len(list2)): df_temp=DataFrame() df_temp=df_temp.append(list2[i]) df_list=df_list.append(df_temp.T) #print(df_list) print(list2[0]) #dfdf=DataFrame() #dfdf=dfdf.append(list2[0]) #print(dfdf) """ 用df作表头:如('ev_vin'),有括号,还有'' """ #df_list.columns = dfdf """ 直接用list作表头即可 """ df_list.columns = list2[0] print(df_list.columns) df_list.drop([''],inplace=True) print(df_list.columns) #df=df.drop(['Unnamed: 7','序号','编号'],axis=1) df_list.to_csv("E:/test/temp.csv")
python读写excel、csv
最新推荐文章于 2024-09-01 22:59:31 发布