如何利用普宁17网站资源创建淘宝店铺并获取代码?
摘要:普宁17网站一起做淘宝,收到网站代码后怎么做,centos7是怎么做网站的,昆明网站制作在线Python文件存读取 想整理一下存读取函数,方便以后直接调用。 读取 1、读xls、csv、xlsx到datafra
普宁17网站一起做淘宝,收到网站代码后怎么做,centos7是怎么做网站的,昆明网站制作在线Python文件存读取
想整理一下存读取函数#xff0c;方便以后直接调用。
读取
1、读xls、csv、xlsx到dataframe
这段代码非常好用#xff0c;这个函数直接把各种格式文件给汇总了
def readDataFile(readPath): # readPath: 数据文件的地址和文件名try:if (readPath[-4:]…Python文件存读取
想整理一下存读取函数方便以后直接调用。
读取
1、读xls、csv、xlsx到dataframe
这段代码非常好用这个函数直接把各种格式文件给汇总了
def readDataFile(readPath): # readPath: 数据文件的地址和文件名try:if (readPath[-4:] .csv):dfFile pd.read_csv(readPath, header0, sep,) # 间隔符为逗号首行为标题行# dfFile pd.read_csv(filePath, headerNone, sep,) # sep: 间隔符无标题行elif (readPath[-4:] .xls) or (readPath[-5:] .xlsx): # sheet_name 默认为 0dfFile pd.read_excel(readPath,header0) # 首行为标题行# dfFile pd.read_excel(filePath, headerNone) # 无标题行elif (readPath[-4:] .dat): # sep: 间隔符header首行是否为标题行dfFile pd.read_table(readPath, sep , header0) # 间隔符为空格首行为标题行# dfFile pd.read_table(filePath,sep,,headerNone) # 间隔符为逗号无标题行else:print(不支持的文件格式。)except Exception as e:print(读取数据文件失败{}.format(str(e)))returnreturn dfFile存入
字典逐行存入csv kind_num_dict{1:0,2:0,3:0,4:2}mid pd.DataFrame(list(kind_num_dict.items()))mid.to_csv(./p1_不同单品累加求和.csv, headerFalse, indexFalse)列表中的字典元素逐行存入xlsx
xlsx_list[{日期:2020-07-01,值:35},{日期:2020-07-02,值:31},{日期:2020-07-03,值:54}]
import pandas as pd#定义一个字典#将字典格式化为DataFrame数据data pd.DataFrame(xlsx_list)#将数据写入Excel中data.to_excel(test.xlsx)
