Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
M
MultiSheet_Standardization
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
JIRA
JIRA
合并请求
0
合并请求
0
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
提交
问题看板
Open sidebar
郑德辉
MultiSheet_Standardization
Commits
7c09887c
提交
7c09887c
authored
6月 21, 2024
作者:
郑德辉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交代码
上级
0e41030b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
65 行增加
和
0 行删除
+65
-0
.gitignore
.gitignore
+5
-0
one_to_more_sheet.py
one_to_more_sheet.py
+60
-0
没有找到文件。
.gitignore
0 → 100644
浏览文件 @
7c09887c
.idea
venv
*.xlsx
\ No newline at end of file
one_to_more_sheet.py
0 → 100644
浏览文件 @
7c09887c
import
pandas
as
pd
import
time
def
process_data
(
datafile
,
target_file
,
column_name
):
start
=
time
.
time
()
pd
.
set_option
(
'mode.chained_assignment'
,
None
)
# Disable warning
# Read the Excel file
df
=
pd
.
read_excel
(
datafile
)
# Create an Excel writer object using pandas
with
pd
.
ExcelWriter
(
target_file
,
engine
=
'xlsxwriter'
)
as
writer
:
# Write original data to the first sheet
df
.
to_excel
(
writer
,
sheet_name
=
'Original Data'
,
index
=
False
)
# Filter out rows where 'column_name' is null
df
=
df
[
df
[
column_name
]
.
notnull
()]
# Extract unique diseases
diseases
=
set
(
df
[
column_name
]
.
tolist
())
# Initialize a list to hold unique sheet names
sheet_unique_list
=
[]
# Process diseases to split by commas and add unique items to the list
for
disease
in
diseases
:
items
=
disease
.
strip
(
','
)
.
split
(
','
)
for
item
in
items
:
if
item
not
in
sheet_unique_list
:
sheet_unique_list
.
append
(
item
)
# Sort 'clear_sheets' in-place
sheet_unique_list
.
sort
(
key
=
len
,
reverse
=
False
)
# print(len(sheet_unique_list))
for
sheet_name
in
sheet_unique_list
:
# Filter dataframe for current sheet name
mask
=
df
[
column_name
]
.
str
.
contains
(
sheet_name
,
na
=
False
)
df_temp
=
df
[
mask
]
df_temp
[
column_name
]
=
sheet_name
# Write to sheet
df_temp
.
to_excel
(
writer
,
sheet_name
=
sheet_name
,
index
=
False
)
end
=
time
.
time
()
runtime
=
end
-
start
print
(
'*************程序运行时间为:'
,
runtime
,
'秒'
)
# Usage
# datafile = r'./诊断标化_第四版.xlsx' # Input file path
# target_file = r'./诊断标化_第四版_诊断拆分.xlsx' # Output file path
# column_name = 'std_dx_desc' # Column name
# process_data(datafile, target_file, column_name)
datafile
=
r'./药品标化第三版.xlsx'
# Input file path
target_file
=
r'./药品标化第三版_药品拆分.xlsx'
# Output file path
column_name
=
'std_rx_desc'
# Column name
process_data
(
datafile
,
target_file
,
column_name
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论