python读取修改csv中的数据
写入数据
with open('DataSavePathSet.csv', 'w') as myFile:
myFile.writelines(self.DataSavePath)
读数据
with open('DataSavePathSet.csv', 'r') as csvfile:
self.DataSavePath =csvfile.readlines()[0]
python读取修改ini中的内容
写入地址
curpath = os.path.dirname(os.path.realpath(__file__))
cfgpath = os.path.join(curpath, "cfg.ini")
conf = configparser.ConfigParser()
conf.read(cfgpath, encoding="utf-8")
# 添加一个select
conf.add_section("DataSaveCfg")
# 往select添加key和value
conf.set("DataSaveCfg", "path", self.DataSavePath)
conf.write(open(cfgpath, "w+", encoding="utf-8")) # w+模式
读地址
conf = configparser.ConfigParser()
# 读ini文件
conf.read("cfg.ini", encoding="utf-8")
Refreshpath = conf.get("DataSaveCfg", "path")
python用DataFrame读存excel
读
import pandas as pd
e = 'data.xlsx'
data = pd.read_excel(e)
写
data.to_excel('data.xlsx',index=None) #会覆盖原文件