python - 在 python 中加速 pd.read_excel
问题描述
我正在编写读取excel数据并将其导入数据库的python。对于 10,000~30,000 条记录是可以的。但是 150,000 多条记录花了我 13 多秒的时间。我怎样才能加快速度?
f = request.files['file']
all_data = {} #insert group data
df = pd.read_excel (f)
df = df.dropna(how='all')
df = df.loc[:, ~df.columns.str.contains('^Unnamed')]
df.index.name = excel_conf['config']['default_config']['identification_column']['name'] #column header identification
df.index += 1 #raise index to a valid one
df = df.fillna("")
########## loop take times #########
for index, row in df.iterrows():
row_dict = []
for key in excel_conf['config']['column_config']: #column header name lists
row_dict.append({
key : row[key]
#key (from excel config) row[key] (row value from excel)
})
index_key = index_keygen(create_blake2s_signature(...)) #just create index key stuffs, i shorted it
# add child data to main
all_data[index_key] = row_dict
#"test_key" : { "key":"value",... }
####################################
insert_db(all_data) #this is fast
解决方案
推荐阅读
- python - Numpy throwing TypeError: cannot unpack non-iterable NoneType object
- swift - (WkWebView) 当我通过输入标签上传文件时,它发生了问题
- php - Laravel 数据库存储会话
- php - 如何使用 PHP 添加 Active Directory 身份验证密码?
- r - 错误无法将“mads”类强制转换为 data.frame
- javascript - JAVASCRIPT - 如何每秒更新变量
- javascript - 如何在反应js中将值从post.map更改为初始状态
- angularjs - 修剪尾随空格并在没有可见输入时显示占位符 - Angularjs
- azure - 在同一个程序集中有多个工作,但在日志/列表中分开
- azure-devops - Azure DevOps 中带有手动步骤的整个管道超时