Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
funggtopp
python-ftsdef
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
python-ftsdef
/
read_excel_sheets_for_No_NaN.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
25 lines (25 loc) · 1.6 KB
main
Breadcrumbs
python-ftsdef
/
read_excel_sheets_for_No_NaN.py
Copy path
Top
File metadata and controls
Code
Blame
25 lines (25 loc) · 1.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def read_excel_sheets_for_No_NaN(file_name='',sheet_name='',skip=[0,0],to_str_column=[],to_concat_column=[],index_col_name='序号'):
'''
主要用于excel表格中出现断行且断行单独占用单元格的情况;主要表现为:断行占用两个或多个垂直单元格;断行单元格相邻单元格为NaN。
特别注意:
索引列在有断行情况时应为NaN;否则,本函数无效!!!
必须有索引列;默认为'序号';否则,函数出错!!!
主要参数:
file_name:缺省='',文件名;
sheet_name:缺省='',文件内表名;
skip:缺省=[0,0],文件首尾跳过行数;有合并单元格式的表头时,一般为[1,0];有末尾汇总行时,一般为[0,1];
to_str_column:缺省=[],读取时转换为字符串的列,如['序号','立项年度'];
to_concat_column:缺省=[],需要处理的有断行问题的列,如['项目名称'];
index_col_name:缺省='序号',索引列,此列在有断行情况时应为NaN;否则,本函数无效;
'''
dtype={}
for item in to_str_column:
dtype[item]=str
df = pd.read_excel(file_name,sheet_name=sheet_name,skiprows=skip[0],skipfooter=skip[1],dtype=dtype)
for index in df[ df.loc[:,index_col_name].isnull()].index:
for item in to_concat_column:
df.loc[index-1,item] = df.loc[index-1,item] + df.loc[index,item]
df = df.drop(df[df[index_col_name].isnull()].index)
df[index_col_name] = df[index_col_name].astype('int')
df = df.set_index(index_col_name,drop=True)
return df
You can’t perform that action at this time.