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
相关推荐
小龙报15 小时前
【算法通关指南:基础算法篇】高精度专题:一篇破除超数运算问题Yupureki15 小时前
《算法竞赛从入门到国奖》算法基础:入门篇-双指针淼淼76315 小时前
Qt工具栏+图页,图元支持粘贴复制,撤销,剪切,移动,删除风筝在晴天搁浅15 小时前
hot100 128.最长连续序列LYFlied15 小时前
【每日算法】LeetCode148. 排序链表小新软件园15 小时前
图片转 Excel 不花钱PDF 转 Excel 工具weisian15115 小时前
入门篇--2-Windows上如何用Conda松管理多个Python版本?努力努力再努力wz15 小时前
【Linux网络系列】:网络+网络编程(UDPsocket+TCPsocket)又是忙碌的一天15 小时前
八大排序之:冒泡排序、快速排序和堆排序hkhkhkhkh12315 小时前
Linux 内核三大核心结构体详解(驱动开发视角)