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
相关推荐
2301_807997381 小时前
代码随想录-day26TL滕1 小时前
从0开始学算法——第一天(认识算法)David.K2 小时前
记录:win10环境手动编译tcl源码过程kyle~2 小时前
机器视觉---Intel RealSense SDK 2.0 开发流程豆沙粽子好吃嘛!3 小时前
windows环境下g++无输出的解决方案一叶龙洲3 小时前
安装Win11+Ubuntu25.10双系统遇到的问题双河子思3 小时前
Visual Studio 编程工程设置代码雕刻家5 小时前
1.4.课设实验-数据结构-单链表-文教文化用品品牌2.0zt1985q5 小时前
本地部署消息代理软件 RabbitMQ 并实现外部访问( Windows 版本 )烤奶要加冰5 小时前
PyCharm 社区版全平台安装指南