import xlrd
import xlwt
import re
import pandas as pd
from datetime import date,datetime
file_path = "C:\\Users\\function_model.xls"
def readexcel():
df = pd.read_excel(file_path ,"配置")
# e_id
# id
# expression
# name
# freq
# column_data = df['e_id']
excel_date = df.loc[:, ['e_id', 'id','expression', 'name', 'freq']]
str1= 'rDataV'
str2 = 'fillMissingDates'
str3 = 'jactor_value'
history3 = 'quantile(B'
trend_judgement = 'judgement('
marginal_trend_media = 'trend_media('
my_array = []
list_name = ["e_id", "expression_index", "expression_name", "expression_factor_freq",
"expression_factor_id", "expression_factor_is_industry", "expression_name"]
my_array.append(list_name)
for index, row in excel_date.iterrows():
expression = row['expression']
e_id = row['e_id']
id = row['id']
name = row['name']
freq = row['freq']
if str1 in expression:
list_index=[e_id ,0 , "B" ,freq ,0 ,0 ,"仅占位"]
my_array.append(list_index)
elif str2 in expression:
pattern = r'\b\d{12}\b'
matches = re.findall(pattern, expression)
list_index = [e_id, 0, "B", freq, matches[0], 1, name[:-4]]
my_array.append(list_index)
elif marginal_trend_media in expression:
pattern = r'\b\d{12}\b'
matches = re.findall(pattern, expression)
list_index = [e_id, 0, "B", freq, matches[0], 1, name[:-5]]
my_array.append(list_index)
elif history3 in expression:
pattern = r'\b\d{12}\b'
matches = re.findall(pattern, expression)
list_index = [e_id, 0, "B", freq, matches[1], 1, name[:-5]]
my_array.append(list_index)
elif trend_judgement in expression:
pattern = r'\b\d{12}\b'
matches = re.findall(pattern, expression)
list_index = [e_id, 0, "B", freq, matches[1], 1, name[:-5]]
my_array.append(list_index)
elif str3 in expression:
list_index = [e_id, 0, "B", freq, 0, 0, "占位"]
my_array.append(list_index)
else:
list_index = [e_id, 0, "B", freq, "待填充", 1, "待填充"]
my_array.append(list_index)
print(my_array)
# 将数组转化为DataFrame
dd = pd.DataFrame(my_array)
dd.to_excel('配置.xlsx', index=False, header=False)
if __name__ == '__main__':
readexcel()
python excel 读取及写入固定格式
stone_tomcat2023-09-06 10:43
相关推荐
xxwxx__2 小时前
C++ STL set 与 map 全套详解:关联式容器、红黑树底层、代码坑点、刷题实战程曦曦3 小时前
MySQL 生产库误删 98 张表后的时间点恢复实战:从 binlog 解析到资金对账郝学胜-神的一滴3 小时前
Effective Python 条款 13:善用星号解包,告别下标切片拆分的坑Logic1013 小时前
C语言/数据结构位运算题解:异或XOR找出流水线上的“独特零件编号“——只出现一次的数字张小姐的猫4 小时前
【AI大模型接入SDK】 —— 数据管理 & 与Session模块进行联动hoaxxcj4 小时前
DeepSeek Harness 本地部署与第三方插件排障实录:从 fetch failed 到 preset not foundcareathers4 小时前
【数据结构】栈mmmmath_35 小时前
LeetCode.018.四数之和淡海水6 小时前
11-02-Unity-Mono-vs-IL2CPP-两种脚本后端的数据结构行为差异梦帮科技6 小时前
Next.js 16 模块化单体实战:App Router、领域模块与 Route Handler 分层