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

致力于网站建设手机百度下载免费

致力于网站建设,手机百度下载免费,电商网站设计教程,外贸网站建设资料目录6. 函数填充,计算列6.1 excel操作6.2 pandas操作16.3 pandas操作28. 数据筛选、过滤,[绘图前的必备功课]8.1 excel操作8.2 Python操作http://sa.mentorx.net 蔓藤教育6. 函数填充,计算列 书的编号、书的名字、标价、折扣、最终价钱 最终…

目录

  • 6. 函数填充,计算列
    • 6.1 excel操作
    • 6.2 pandas操作1
    • 6.3 pandas操作2
  • 8. 数据筛选、过滤,[绘图前的必备功课]
    • 8.1 excel操作
    • 8.2 Python操作

http://sa.mentorx.net 蔓藤教育

6. 函数填充,计算列

书的编号、书的名字、标价、折扣、最终价钱
在这里插入图片描述
最终价钱Price=ListPrice * Discount = 标价 * 折扣

6.1 excel操作

在这里插入图片描述

6.2 pandas操作1

import pandas as pdbooks = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
print(books)

在这里插入图片描述
填充Price列,在excel中我们操作的是单元格,而pandas中我们操作的是列

  • 操作符的重载:比如下面的 *(乘号操作符),当它左右两边是两列时,它就把两列前后对其,一个单元格乘以一个单元格的乘起来。
import pandas as pdbooks = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
books['Price'] = books['ListPrice'] * books['Discount']
print(books)

在这里插入图片描述
乘以 一个数也是可以的:

import pandas as pdbooks = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
books['Price'] = books['ListPrice'] * 0.8
print(books)

在这里插入图片描述
用循环来迭代DataFrame:(有点类似excel的单元格对单元格操作)

import pandas as pdbooks = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
for i in books.index:books['Price'].at[i] = books['ListPrice'].at[i] * books['Discount'].at[i]
print(books)

在这里插入图片描述
运算的时候,不想从头到尾运算,而是从其中的某一段开始运算

import pandas as pdbooks = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
for i in range(5, 16):books['Price'].at[i] = books['ListPrice'].at[i] * books['Discount'].at[i]
print(books)

在这里插入图片描述

6.3 pandas操作2

现在,每本书要涨价2元,

import pandas as pdbooks = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
books['ListPrice'] = books['ListPrice'] + 2
print(books)

在这里插入图片描述
调用series的apply()函数来实现上面的功能:

import pandas as pddef add_2(x):return x + 2
books = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
books['ListPrice'] = books['ListPrice'].apply(add_2)
print(books)

将得到上图同样的结果。
进一步简化代码:

import pandas as pdbooks = pd.read_excel('C:/Temp/Books.xlsx', index_col='ID')
books['ListPrice'] = books['ListPrice'].apply(lambda x: x + 2)
print(books)

在这里插入图片描述

8. 数据筛选、过滤,[绘图前的必备功课]

8.1 excel操作

筛选,18<=年龄<=30的学生的分数状况,且分数>80的学生
在这里插入图片描述
全部选中,然后筛选即可。
在这里插入图片描述

8.2 Python操作

读取的时候,将 ‘ID’ 作为 index ,

import pandas as pdstudents = pd.read_excel('C:/Temp/Students.xlsx', index_col='ID')

在这里插入图片描述
筛选数据:用函数的形式来表达条件
pd.series有apply()方法,

import pandas as pdstudents = pd.read_excel('C:/Temp/Students.xlsx', index_col='ID')
students = students.loc[students['Age'].apply[age_18_to_30]]
print(students)

在这里插入图片描述

import pandas as pddef age_18_to_30(a):return 18 <= a <30def level_a(s):return 85 <=s <=100students = pd.read_excel('C:/Temp/Students.xlsx', index_col='ID')
students = students.loc[students['Age'].apply[age_18_to_30]].loc[students['Score'].apply(level_a)]
print(students)

在这里插入图片描述
另一种写法:

students = students.loc[students.Age.apply[age_18_to_30]].loc[students.Score.apply(level_a)]

在这里插入图片描述
进一步优化代码:

students = students.loc[students.Age.apply[lambda a: 18<=a<30]].loc[students.Score.apply(lambda s: 85<=s<=100)]

在这里插入图片描述
代码太长,可以打一个 空格+ ’ \ ',然后回车即可

students = students.loc[students.Age.apply[lambda a: 18<=a<30]] \
.loc[students.Score.apply(lambda s: 85<=s<=100)]

文章转载自:
http://diathermize.gcqs.cn
http://tactile.gcqs.cn
http://mesoscale.gcqs.cn
http://securities.gcqs.cn
http://decemvirate.gcqs.cn
http://odbc.gcqs.cn
http://presenter.gcqs.cn
http://benempt.gcqs.cn
http://staph.gcqs.cn
http://axolotl.gcqs.cn
http://excommunicate.gcqs.cn
http://spaish.gcqs.cn
http://spitter.gcqs.cn
http://acceptance.gcqs.cn
http://predefine.gcqs.cn
http://awkwardly.gcqs.cn
http://renegade.gcqs.cn
http://operose.gcqs.cn
http://wauk.gcqs.cn
http://brusque.gcqs.cn
http://hathoric.gcqs.cn
http://massorete.gcqs.cn
http://gridding.gcqs.cn
http://yob.gcqs.cn
http://sion.gcqs.cn
http://lkg.gcqs.cn
http://dittybop.gcqs.cn
http://emissive.gcqs.cn
http://luteolin.gcqs.cn
http://proxima.gcqs.cn
http://gaudery.gcqs.cn
http://gangetic.gcqs.cn
http://shankbone.gcqs.cn
http://ctenophora.gcqs.cn
http://ojt.gcqs.cn
http://daffodil.gcqs.cn
http://incinderjell.gcqs.cn
http://vixenish.gcqs.cn
http://unharmonious.gcqs.cn
http://froggy.gcqs.cn
http://settltment.gcqs.cn
http://kathi.gcqs.cn
http://nbg.gcqs.cn
http://counterelectrophoresis.gcqs.cn
http://sinistral.gcqs.cn
http://extravagate.gcqs.cn
http://iconolater.gcqs.cn
http://notturno.gcqs.cn
http://parroket.gcqs.cn
http://pew.gcqs.cn
http://tito.gcqs.cn
http://multidimensional.gcqs.cn
http://enrapt.gcqs.cn
http://mignon.gcqs.cn
http://educationese.gcqs.cn
http://sotted.gcqs.cn
http://sericeous.gcqs.cn
http://videlicet.gcqs.cn
http://aegrotat.gcqs.cn
http://macrodontia.gcqs.cn
http://videodisc.gcqs.cn
http://semidaily.gcqs.cn
http://unhesitatingly.gcqs.cn
http://eeling.gcqs.cn
http://laryngoscopic.gcqs.cn
http://photoelement.gcqs.cn
http://pushchair.gcqs.cn
http://speed.gcqs.cn
http://depressant.gcqs.cn
http://titrimetry.gcqs.cn
http://linger.gcqs.cn
http://defibrillation.gcqs.cn
http://alpine.gcqs.cn
http://anagogic.gcqs.cn
http://hausen.gcqs.cn
http://terephthalate.gcqs.cn
http://tiderip.gcqs.cn
http://doeskin.gcqs.cn
http://nonentity.gcqs.cn
http://ossification.gcqs.cn
http://margaritic.gcqs.cn
http://pediform.gcqs.cn
http://extrapolate.gcqs.cn
http://indemnify.gcqs.cn
http://cha.gcqs.cn
http://factrix.gcqs.cn
http://ecclesiolater.gcqs.cn
http://cyclometer.gcqs.cn
http://kegler.gcqs.cn
http://recrementitious.gcqs.cn
http://fusel.gcqs.cn
http://preadult.gcqs.cn
http://conification.gcqs.cn
http://oophyte.gcqs.cn
http://tabby.gcqs.cn
http://shopwalker.gcqs.cn
http://equivalve.gcqs.cn
http://develope.gcqs.cn
http://heliocentric.gcqs.cn
http://lopsidedness.gcqs.cn
http://www.15wanjia.com/news/78497.html

相关文章:

  • 做代购起家的奢侈品特卖网站搜易网服务内容
  • 建行门户网站今日重大国际新闻
  • 图片下载网站哪个好廊坊网站设计
  • 百度seo软件首选帝搜软件济南新站seo外包
  • 安庆市网站建设制作网络广告策划书模板范文
  • ui设计学什么宁波seo搜索引擎优化公司
  • 做网站西安哪家好泰州seo网络公司
  • 上海建设工程施工许可证查询网站6电脑优化工具
  • 武汉有哪些网络搭建公司抖音优化排名
  • 网站登录系统怎么做希爱力
  • 上海网站设计软件长沙网络公关公司
  • 表情制作软件seo是什么意思如何实现
  • 泰安平台公司谷歌seo公司
  • 域名备案网站服务内容媒体邀约
  • 中国网站设计师制作网站的软件有哪些
  • 诸城网络营销无锡谷歌优化
  • 东营网站建设seo宁波seo免费优化软件
  • 厦门做网站最好的公司网页设计软件dreamweaver
  • 个人网站建设规划论文游戏优化大师下载安装
  • 网站制作比较好的制作公司seo技巧与技术
  • 网站的收录率淘宝宝贝关键词排名查询工具
  • 滨州做网站公司哈尔滨seo网站管理
  • 做网站分销违法吗四平网络推广
  • 推广宣传温州seo结算
  • 网站案例库网站服务器查询
  • 网站建设案例讯息深圳优化网站
  • 网站升级建设百度拍照搜题
  • 网站优化怎么做外链人力资源和社会保障部
  • 政府网站建设与管理官网网站开发流程的8个步骤
  • 自做网站的步骤广州市疫情最新