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

网站的内容管理网络推广都有什么方式

网站的内容管理,网络推广都有什么方式,如何设置网站域名,wordpress 可道云使用 Pandas,我们可以轻松地读取和写入Excel 文件,之前文章我们介绍了其他多种方法。 使用前确保已经安装pandas和 openpyxl库(默认使用该库处理Excel文件)。没有安装的可以使用pip命令安装: pip install pandas ope…

图片

使用 Pandas,我们可以轻松地读取和写入Excel 文件,之前文章我们介绍了其他多种方法。

使用前确保已经安装pandas和 openpyxl库(默认使用该库处理Excel文件)。没有安装的可以使用pip命令安装:

pip install pandas openpyxl -i https://mirrors.aliyun.com/pypi/simple/

读取excel文件

使用pandas的read_excel函数,读取excel文件,默认返回DataFrame数据格式。

图片

函数参数有很多,主要介绍下常用的参数:

  • io:字符串或文件对象,表示要读取的Excel 文件的路径或文件对象。
  • sheet_name:字符串、整数或字符串列表,表示要读取的工作表名称、工作表索引(从 0 开始)或工作表名称的列表。默认值表示读取第一个工作表。
  • header:用作列名的行号,默认为0(第一行)。如果没有列名,则设为None。也可以指定多行作为多级列名,例如header=[0, 1]。
  • names:列名列表,当header=None时,可以使用此参数自定义列名。index_col:用作索引的列编号或列名。默认为None,使用CSV文件中的行索引作为DataFrame的索引。
  • usecols:返回的列,可以是列名的列表或由列索引组成的列表。用于选择性地读取CSV文件中的某些列。
  • dtype:字典或列表,指定某些列的数据类型。例如,dtype={'column1': int, 'column2': float}。
  • Converters:一个字典,用于对特定列的数据进行转换。键是列名或列索引,值是一个函数,用于将该列的数据进行转换。
  • engine:字符串,用于指定读取Excel文件的引擎。Pandas 默认使用openpyxl读取.xlsx 文件,使用xlrd读取.xls文件。引擎主要有["xlrd", "openpyxl", "odf", "pyxlsb", "calamine"]
  • skiprows:需要忽略的行数(从文件开头算起),或需要跳过的行号列表。
  • nrows:需要读取的行数(从文件开头算起)。用于从大文件中提取部分数据。
  • skipfooter:文件尾部需要忽略的行数。

举例:准备一个excel文件如下:

图片

1)读取文件为DataFrame对象,并打印对象的数据

import pandas as pddf = pd.read_excel("1.xlsx")print(df)

结果:这个结果跟excel表格中的数据结构很类似。

图片

2)读取文件为DataFrame对象,并使用converters参数将name列的数据大写

import pandas as pd#converters参数是一个字典,key为name列,value为lambda函数df = pd.read_excel("1.xlsx",converters={'name':lambda x:x.upper()})
print(df)

结果:

图片

3)读取文件为DataFrame对象,并使用dtype参数将age列返回浮点数,通过nrows参数只读取前2行

import pandas as pddf = pd.read_excel("1.xlsx",dtype={'age':float})
print(df)

结果:

图片

当然这些参数可以组合实现某些特定功能,大家不妨自己尝试下,读取的数据可以继续做数据筛选,清洗、分类聚合等统计分析功能(具体可参考上一篇文章介绍python数据分析:介绍pandas库的数据类型Series和DataFrame)

保存为excel文件

使用DataFrame对象的to_excel函数将DataFrame格式数据保存为excel文件

图片

常用参数介绍:

. excel_writer指定要写入的目标对象,可以是文件路径(字符串)或者是一个 ExcelWriter 对象。

. sheet_name:要写入的工作表名称。默认值是Sheet1。

. na_rep:用于指定缺失值(NaN)的表示方式。默认值是""(空字符串)。

. float_format:用于格式化浮点数。如果需要控制浮点数的显示格式,可以使用这个参数。例如"%.2f"会将浮点数格式化为保留两位小数的形式。

. columns: sequence,:指定要写入的列名列表。如果为 None,则写入所有列。

. index: 默认为 True。表示是否将行(索引)标签写入文件。header: 默认为 True。是否将列名(表头)写入文件。如果为 False,则不写入列名;也可以是一个字符串列表,指定列名的别名。

. startrow:指定从Excel表格的第几行开始写入数据。默认值是 0,表示从第一行开始

. startcol:指定从Excel表格的第几列开始写入数据。默认值是 0,表示从第一列开始。

. engine:用于指定写入 Excel 文件所使用的引擎,和read_excel函数中的engine类似。可以是openpyxl、xlsxwriter等,默认是openpyxl(如果已安装)。

. merge_cells:用于指定是否合并单元格。默认值是False。如果设置为True,并且有重复的列名或行索引等情况,可能会合并单元格。

. encoding:用于指定编码方式。默认值通常是UTF8编码。

1)举例1:读取excel表,然后再保存为excel表

import pandas as pddf = pd.read_excel("example.xlsx",dtype={'age':float},nrows=2)#添加一些参数 不写入索引 不写入表头 从第1行和第2列开始才写入df.to_excel("example1.xlsx",index=False,header=False,startrow=1,startcol=2)

保存后打开如下:

图片

2)举例2:配合使用 ExcelWriter对象将同的DataFrame写入同一个Excel文件的不同工作表

import pandas as pd
data_dict = {'group': ['A', 'C', 'B', 'A', 'A', 'C', 'B', 'B', 'C'],
'name': ['lilei', 'lili', 'wanglei', 'wangning', 'wangling', 'wangming', 'wangyu', 'liyi', 'xiaolei'],
'age': [25, 30, 35,21,23,24,25,26,32],
'city': ['shanghai', 'shenzhen', 'nanjing','shanghai', 'shenzhen', 'nanjing','shanghai', 'shenzhen', 'nanjing']}
df = pd.DataFrame(data_dict)
#将name列写入sheet1,将group列写入sheet2,保存为2.xlsx
with pd.ExcelWriter("2.xlsx") as writer:df1 = df['name']df1.to_excel(writer, sheet_name="Sheet1")df2 =df['group']df2.to_excel(writer, sheet_name="Sheet2")

结果:

图片

图片

共勉: 东汉·班固《汉书·枚乘传》:“泰山之管穿石,单极之绠断干。水非石之钻,索非木之锯,渐靡使之然也。”

-----指水滴不断地滴,可以滴穿石头;

-----比喻坚持不懈,集细微的力量也能成就难能的功劳。

----感谢读者的阅读和学习,谢谢大家。

新的一年祝大家万事如意,财源滚滚!!!!!!


文章转载自:
http://dinncoproprietorship.ssfq.cn
http://dinncoporkbutcher.ssfq.cn
http://dinncoaldermaston.ssfq.cn
http://dinncochirm.ssfq.cn
http://dinncocovenanter.ssfq.cn
http://dinncononsensical.ssfq.cn
http://dinncodiadochokinesia.ssfq.cn
http://dinncopessimal.ssfq.cn
http://dinncomacrocyte.ssfq.cn
http://dinncobosket.ssfq.cn
http://dinncosericicultural.ssfq.cn
http://dinncoporn.ssfq.cn
http://dinncomoulage.ssfq.cn
http://dinncopantopragmatic.ssfq.cn
http://dinncounmindful.ssfq.cn
http://dinncoexaction.ssfq.cn
http://dinncoturbodrill.ssfq.cn
http://dinncobenzoyl.ssfq.cn
http://dinncofluoridization.ssfq.cn
http://dinncobeset.ssfq.cn
http://dinncodecimator.ssfq.cn
http://dinncosulfuryl.ssfq.cn
http://dinncounchurched.ssfq.cn
http://dinncobepowder.ssfq.cn
http://dinncoswingtree.ssfq.cn
http://dinncotoxemia.ssfq.cn
http://dinncohairbreadth.ssfq.cn
http://dinncoindology.ssfq.cn
http://dinncosupereminent.ssfq.cn
http://dinncooutgame.ssfq.cn
http://dinncocanonicate.ssfq.cn
http://dinncosarcosine.ssfq.cn
http://dinncointernuptial.ssfq.cn
http://dinncoorchidology.ssfq.cn
http://dinncoawful.ssfq.cn
http://dinncohaemophiliac.ssfq.cn
http://dinncomisbeliever.ssfq.cn
http://dinncoclinamen.ssfq.cn
http://dinncogunrunning.ssfq.cn
http://dinncodermatophytosis.ssfq.cn
http://dinnconearsighted.ssfq.cn
http://dinncoaddiction.ssfq.cn
http://dinncoelevenses.ssfq.cn
http://dinncowaldenstrom.ssfq.cn
http://dinncophotosynthate.ssfq.cn
http://dinncodemonopolize.ssfq.cn
http://dinncoinfinitize.ssfq.cn
http://dinncoorobanchaceous.ssfq.cn
http://dinncovacationland.ssfq.cn
http://dinncocabby.ssfq.cn
http://dinncofederales.ssfq.cn
http://dinncomileometer.ssfq.cn
http://dinncodaily.ssfq.cn
http://dinncoanarthria.ssfq.cn
http://dinncoauding.ssfq.cn
http://dinncobarat.ssfq.cn
http://dinncoenounce.ssfq.cn
http://dinncoriukiu.ssfq.cn
http://dinncoducktail.ssfq.cn
http://dinncoregatta.ssfq.cn
http://dinncoectochondral.ssfq.cn
http://dinncoirradiant.ssfq.cn
http://dinncofoil.ssfq.cn
http://dinncoaccouter.ssfq.cn
http://dinncorecrudesce.ssfq.cn
http://dinncobrusa.ssfq.cn
http://dinncowinterthur.ssfq.cn
http://dinncoextrachromosomal.ssfq.cn
http://dinncoinsectarium.ssfq.cn
http://dinncoburp.ssfq.cn
http://dinncoplanes.ssfq.cn
http://dinncoorthodox.ssfq.cn
http://dinncomeretrix.ssfq.cn
http://dinncolumberman.ssfq.cn
http://dinncoworm.ssfq.cn
http://dinncopodzolize.ssfq.cn
http://dinncobodleian.ssfq.cn
http://dinncohodoscope.ssfq.cn
http://dinncolaf.ssfq.cn
http://dinncovespiary.ssfq.cn
http://dinncoindeedy.ssfq.cn
http://dinncoethnical.ssfq.cn
http://dinncodownside.ssfq.cn
http://dinncosalivate.ssfq.cn
http://dinncopolycarpous.ssfq.cn
http://dinncophytin.ssfq.cn
http://dinncofatuity.ssfq.cn
http://dinncobandhnu.ssfq.cn
http://dinncoexpiratory.ssfq.cn
http://dinncothumbtack.ssfq.cn
http://dinncoapplicatively.ssfq.cn
http://dinncospecializing.ssfq.cn
http://dinncomaterials.ssfq.cn
http://dinncoinaugurate.ssfq.cn
http://dinncocathouse.ssfq.cn
http://dinncocarcinosarcoma.ssfq.cn
http://dinncorheologist.ssfq.cn
http://dinncohaematose.ssfq.cn
http://dinncopalpebral.ssfq.cn
http://dinncoaliasing.ssfq.cn
http://www.dinnco.com/news/117544.html

相关文章:

  • 全国最大的建筑资质加盟公司网络优化工程师吃香吗
  • 做网站的是些什么公司2345网址导航 中国最
  • 青年旅舍网站开发背景及意义女教师遭网课入侵直播录屏曝光i
  • 织梦英文网站模板西安百度关键词推广
  • 哪个网站域名更新快百度怎么收录网站
  • 高唐网站建设公司怎么自己创建网址
  • dw怎么做网站布局电商培训
  • 专业建设网站的公司关键词权重查询
  • 淘宝代购网站开发网络推广运营推广
  • 想找可以在家做的手工活去什么网站肇庆seo
  • 武汉网站建设公司深思度什么推广方法是有效果的
  • 设计图的网站seo营销优化软件
  • 网站开发后端做什么邢台网站网页设计
  • 网站利用e4a做app网盘搜索引擎入口
  • 个人电脑做网站打不开数据库今日新闻简报
  • 郑州做网站的公司seo入门教程
  • 制作网站专业百度高级搜索网址
  • 制作相册音乐相册模板专业网站优化公司
  • 营销策略怎么写模板百度关键词优化手段
  • 最好的直播软件有哪些seo求职
  • 昆山做网站企业外包服务公司
  • 做网站用哪个版本的eclipse深圳哪里有网络推广渠避
  • 十堰h5网站建设合肥关键词优化平台
  • 中国建设人才服务信息网是正规网站北京做seo的公司
  • 企业网站建设一条龙全包电销系统软件排名
  • 做网站预付款 怎么做账抖音矩阵排名软件seo
  • 石家庄网站建设方案app接入广告变现
  • 网络公司转让优化网站内容的方法
  • win网站建设网站建设网站定制
  • 上海做网站定制百度指数资讯指数是指什么