python1A 之 文件存取读入

一、csv

读取csv, index_col 较为常用;encoding = 'GBK' 在输入法出bug的时候可以添加,以中文读取;low_memory = False 在大内存的时候添加

pd.read_csv(" ***.csv ")

pd.read_csv(" ***.csv ", index_col = 0) : 将id列变index

pd.read_csv(" ***.csv ", index_col = 0, encoding = 'GBK' , low_memory = False )

输出: index是否要索引,header是否要列名,True就是需要

outputpath=path+'\数据\行业名称.csv'

industryname.to_csv(outputpath,index=True,header=True)

二、pickle的优势在于其速度

存入pickle文件:

import pickle

with open('***.pkl', 'wb') as file:

pickle.dump(rawdata1,file)

读pickle 文件:

with open('宏观定价***.pkl', 'rb') as file:

rawdata1=pickle.load(file)

三、excel优势在于多表格,劣势在于速度和内存

读取excel:注:应用程序在单斜杠层面可能出现错,可以使用双斜杠

方法1:

Excel = pd.ExcelFile(output_temp_path + "估值表数据汇总.xlsx")

position1 = Excel.parse("position", index_col=0) # 将position的表单抽出来

方法2:

position = pd.read_excel(path + "估值表数据汇总.xlsx", sheet_name = 'position', index_col = 0)

输出到excel:

方法1:

outputpath='E:\etf\离散度.xlsx'

compare.to_excel(outputpath,index=True,header=True,sheet_name='年数据')

方法二:多个excel:

with pd.ExcelWriter('E:\\python\\bollingersignal.xlsx') as writer:

log1.to_excel(writer,index=True,header=True,sheet_name='bollinger1')

log2.to_excel(writer,index=True,header=True,sheet_name='bollinger2')

writer.save()

writer.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值