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
相关推荐
8Qi88 分钟前
LeetCode 23. 合并 K 个升序链表 —— 小顶堆(PriorityQueue)QiLinkOS27 分钟前
《打破“用爱发电”:一种基于 Gitee 与时间戳的开源权益分配机制探索》阿汤猫6661 小时前
基于OpenCode的Harness架构实战v2.2(windows系统)Boom_Shu2 小时前
长方形的关系xiaoshuaishuai82 小时前
C# AvaloniaUI 资源找不到报错思麟呀3 小时前
C++11并发编程:call_once一次性执行+atomic原子类型+CAS无锁编程+自旋锁爱讲故事的3 小时前
操作系统第一讲复习:为什么学习操作系统,以及操作系统到底在做什么?Lsk_Smion3 小时前
力扣实训 _ [543].二叉树的直径 _ [23].合并K个升序列表ID_180079054736 小时前
淘宝商品详情数据接口深度解析:架构、鉴权、数据结构与实战散峰而望6 小时前
【算法练习】算法练习精选:陶陶摘苹果(基础+升级)、Music Notes、字串变换,你能AC几道?