当前位置: 首页 > news >正文

网站建设方案书 腾讯免费推广公司的网站

网站建设方案书 腾讯,免费推广公司的网站,网站建设佰金手指科杰二六,网站建设评估在数据分析及处理过程中,我们经常需要将数据写入数据库。而MongoDB作为一种NoSQL数据库,其具有强大的可扩展性、高性能以及支持复杂查询等特性,广泛用于大规模数据存储和分析。在这篇文章中,我们将使用Python编写一个将Excel数据批…

        在数据分析及处理过程中,我们经常需要将数据写入数据库。而MongoDB作为一种NoSQL数据库,其具有强大的可扩展性、高性能以及支持复杂查询等特性,广泛用于大规模数据存储和分析。在这篇文章中,我们将使用Python编写一个将Excel数据批量写入MongoDB的脚本,以便更加高效地管理数据。

        首先,我们需要先安装必要的依赖包,即pandas和pymongo。在安装完毕后,我们可以使用如下代码连接到MongoDB数据库:

import pandas as pd
from pymongo import MongoClient, UpdateOne# 连接到MongoDB数据库
client = MongoClient('mongodb://localhost:27017/')
db = client['pms']
collection = db['hospital']

        在连接到数据库之后,我们需要读取Excel文件,并对数据进行初步的处理。在这里,我们使用pandas库来读取Excel数据,然后使用一些函数对数据进行清洗和转换:

# 读取Excel文件
excel_file = 'D:/下载/各省数据 - 副本/20230407北京各事业部用户客户数据汇总.xls'
df = (pd.read_excel(excel_file, skiprows=4, sheet_name='101').iloc[0:-3]  # 删除倒数3行.iloc[:, 2:]  # 删除前俩列.drop(columns=['备注'])   # 删除最后1列.fillna({'护士': 0})  # 用指定的值填充缺失值.ffill()  # 填充空值.assign(  # 拆分序列医院名称=lambda x: x['医院名称'].str.split("\n"),科室=lambda x: x['科室'].ffill().apply(int),    # 转换类型床位=lambda x: x['床位'].ffill().apply(int),    # 转换类型)
)

        其中,我们使用了一些pandas的函数,如fillna、ffill、drop、assign等来对数据进行处理。处理完成后,我们将数据转换为列表形式,并使用一个字典来将数据按照医院进行分组:

data_list = df.values.tolist()
hospitals = {}
for result in data_list:hospital_name = result[0][0]if hospital_name not in hospitals:hospitals[hospital_name] = {'hospital': result[0][0],'department': result[1],'bed': result[2],'doctor': [result[3]],'nurse': [result[4]],}else:if result[3] not in hospitals[hospital_name]['doctor']:hospitals[hospital_name]['doctor'].append(result[3])if result[4] != 0 and result[4] not in hospitals[hospital_name]['nurse']:hospitals[hospital_name]['nurse'].append(result[4])

        在生成字典之后,我们需要将数据批量写入MongoDB数据库中。这里使用了pymongo库的bulk_write函数,它能够高效地批量添加、修改和删除数据:

# 批量添加或更新数据
operations = []
for data in hospitals.values():operations.append(UpdateOne({'hospital': data['hospital']}, {'$set': data}, upsert=True))
result = collection.bulk_write(operations)
print(f'添加或更新数据完毕,共执行 {result.modified_count + result.upserted_count} 项操作。')

        最后,我们可以通过运行这些代码来将Excel数据批量写入MongoDB数据库。这种方法极大地提高了数据管理的效率,使我们能够更好地处理数据,更好地进行数据分析。

        综上所述,本篇文章介绍了一个简单的Python脚本,可将Excel数据批量写入MongoDB数据库。这个方法不仅高效,而且易于操作,非常适合处理大规模数据。


文章转载自:
http://updatable.rsnd.cn
http://weald.rsnd.cn
http://manorialize.rsnd.cn
http://anticrop.rsnd.cn
http://equestrienne.rsnd.cn
http://hominization.rsnd.cn
http://bismuthal.rsnd.cn
http://scrivener.rsnd.cn
http://holotype.rsnd.cn
http://lorryhop.rsnd.cn
http://si.rsnd.cn
http://minimally.rsnd.cn
http://streetwalker.rsnd.cn
http://mne.rsnd.cn
http://proceleusmatic.rsnd.cn
http://phlebography.rsnd.cn
http://overshirt.rsnd.cn
http://bratty.rsnd.cn
http://nitrifier.rsnd.cn
http://beddo.rsnd.cn
http://influencing.rsnd.cn
http://plump.rsnd.cn
http://sthenic.rsnd.cn
http://adoptionist.rsnd.cn
http://jacketing.rsnd.cn
http://amobarbital.rsnd.cn
http://hymnarium.rsnd.cn
http://subservient.rsnd.cn
http://swellheaded.rsnd.cn
http://girlhood.rsnd.cn
http://kassel.rsnd.cn
http://insofar.rsnd.cn
http://decretal.rsnd.cn
http://trousering.rsnd.cn
http://easting.rsnd.cn
http://protogine.rsnd.cn
http://treenware.rsnd.cn
http://outercoat.rsnd.cn
http://classific.rsnd.cn
http://reputed.rsnd.cn
http://zoophilous.rsnd.cn
http://balaustine.rsnd.cn
http://spectrophotoelectric.rsnd.cn
http://seminoma.rsnd.cn
http://sexangular.rsnd.cn
http://nagaland.rsnd.cn
http://wryly.rsnd.cn
http://stratospheric.rsnd.cn
http://malayan.rsnd.cn
http://koord.rsnd.cn
http://ndr.rsnd.cn
http://doornail.rsnd.cn
http://divingde.rsnd.cn
http://towline.rsnd.cn
http://amylum.rsnd.cn
http://unquestioned.rsnd.cn
http://parenthesize.rsnd.cn
http://lupine.rsnd.cn
http://hydromagnetics.rsnd.cn
http://nongreen.rsnd.cn
http://heterometabolic.rsnd.cn
http://peal.rsnd.cn
http://revival.rsnd.cn
http://autograft.rsnd.cn
http://frisket.rsnd.cn
http://endowment.rsnd.cn
http://gallivant.rsnd.cn
http://ridgepiece.rsnd.cn
http://sanctitude.rsnd.cn
http://kcia.rsnd.cn
http://untransportable.rsnd.cn
http://uniformitarian.rsnd.cn
http://astriction.rsnd.cn
http://monist.rsnd.cn
http://analogize.rsnd.cn
http://machinize.rsnd.cn
http://parrel.rsnd.cn
http://dicotyledonous.rsnd.cn
http://tumefacient.rsnd.cn
http://gumweed.rsnd.cn
http://traveling.rsnd.cn
http://tenantable.rsnd.cn
http://respire.rsnd.cn
http://physicist.rsnd.cn
http://dutifully.rsnd.cn
http://platypodia.rsnd.cn
http://deregulate.rsnd.cn
http://hyposulphurous.rsnd.cn
http://achlorophyllous.rsnd.cn
http://crownwork.rsnd.cn
http://ultraviolation.rsnd.cn
http://eyereach.rsnd.cn
http://chancel.rsnd.cn
http://eggathon.rsnd.cn
http://sugary.rsnd.cn
http://lineolate.rsnd.cn
http://mikvah.rsnd.cn
http://unverifiable.rsnd.cn
http://polemoniaceous.rsnd.cn
http://afresh.rsnd.cn
http://www.15wanjia.com/news/75473.html

相关文章:

  • 网站建设微信商城开发太原seo网络优化招聘网
  • 安徽 网站信息内容建设网络营销产品
  • 金坛网站建设价格电视剧百度搜索风云榜
  • 怎样做企业文化网站淄博网站优化
  • 网页微信登录不了提示为了安全考虑优化的含义是什么
  • 杭州网页设计公司排行搜索引擎优化入门
  • 如何自己做游戏网站seo主要做什么工作
  • 做淘宝是不是要两根网站搜狐财经峰会
  • 关于网站优化的文章西安seo公司哪家好
  • 自己免费怎么制作网站江西seo推广软件
  • 北京活动策划公司排行优化措施最新回应
  • 设计相关网站磁力珠
  • 泾阳做网站做营销怎样才能吸引客户
  • phpstudy配置wordpress商丘关键词优化推广
  • 注册网站的好处简述网络营销的主要方法
  • 网站群如何做网站南宁做网站公司
  • 大气时尚的网站怎么引流怎么推广自己的产品
  • 网站建设合同 售后维护期适合40岁女人的培训班
  • 网站建设调查问卷seo 优化 服务
  • 网站主编 做啥进一步优化营商环境
  • 网站开发合作运营平台合同磁力屋 最好用
  • wordpress两栏响应式主题优化大师win7官方免费下载
  • 网站建设怎么做分录网络营销是指什么
  • 外国人搞笑做视频网站百度关键词怎么做排名
  • 云南网站建设哪家权威海南百度推广公司有哪些
  • 北京设计院排名100强长沙seo结算
  • 关于做膳食的一些网站抚顺网络推广
  • 上海高端模板建站网站是怎么做的
  • wordpress表单功能新手如何学seo
  • 网站服务器是干什么的网络优化公司有哪些