Python数据分析之pandas入门
一、pandas库简介
二、pandas库的安装
三、Series的使用

import pandas as pd
ser=pd.Series([12,33,55,66])
print(ser) '''输出为
0 12
1 33
2 55
3 66
dtype: int64
'''
运行上面的代码,可以知道,如果不指定标签,那么默认标签就是从0开始递增,我们也可以在声明一个Series对象时给它指定标签:
import pandas as pd
ser=pd.Series([12,33,55,66],index=['a','s','d','f'])
print(ser) '''输出为:
a 12
s 33
d 55
f 66
dtype: int64
'''
import pandas as pd
ser=pd.Series([12,33,55,66])
print(ser[2])
ser[2]=99
print(ser[2]) '''输出为:
55
99
'''
import pandas as pd
ser=pd.Series([12,33,55,66])
ser2=ser/2
print(ser2) import numpy as np
print(np.log(ser)) '''输出为:
0 6.0
1 16.5
2 27.5
3 33.0
dtype: float64
0 2.484907
1 3.496508
2 4.007333
3 4.189655
dtype: float64
'''
import pandas as pd
dic={'wife':'kathy','son':'mary','mother':'lily','father':'tom'}
ser=pd.Series(dic)
print(ser) '''输出为:
wife kathy
son mary
mother lily
father tom
dtype: object
'''
四、DataFrame的使用

import pandas as pd
dic={'name':['tom','mary','john','mike'],'age':[14,15,77,45],'sex':['男','男','女','男']}
frame=pd.DataFrame(dic)
print(frame) '''输出为:
name age sex
0 tom 14 男
1 mary 15 男
2 john 77 女
3 mike 45 男
'''
import pandas as pd
dic={'name':['tom','mary','john','mike'],'age':[14,15,77,45],'sex':['男','男','女','男']}
frame=pd.DataFrame(dic)
frame['weight']=[89,99,145,123]
print(frame) '''输出为:
name age sex weight
0 tom 14 男 89
1 mary 15 男 99
2 john 77 女 145
3 mike 45 男 123
'''
import pandas as pd
dic={'name':['tom','mary','john','mike'],'age':[14,15,77,45],'sex':['男','男','女','男']}
frame=pd.DataFrame(dic)
print(frame.T) '''输出为:
0 1 2 3
name tom mary john mike
age 14 15 77 45
sex 男 男 女 男
'''
五、Series与DataFrame对象之间的运算
import pandas as pd
import numpy as np
frame=pd.DataFrame(np.arange(16).reshape((4,4)),index=['age','name','sex','weight'],columns=['john','tom','mary','cathy'])
print(frame)
ser=pd.Series(np.arange(4),index=['john','tom','mary','cathy'])
print(ser)
res=frame-ser
print(res) '''输出为:
john tom mary cathy
age 0 1 2 3
name 4 5 6 7
sex 8 9 10 11
weight 12 13 14 15 john 0
tom 1
mary 2
cathy 3
dtype: int32 john tom mary cathy
age 0 0 0 0
name 4 4 4 4
sex 8 8 8 8
weight 12 12 12 12
'''
Python数据分析之pandas入门的更多相关文章
- Python 数据处理库 pandas 入门教程
Python 数据处理库 pandas 入门教程2018/04/17 · 工具与框架 · Pandas, Python 原文出处: 强波的技术博客 pandas是一个Python语言的软件包,在我们使 ...
- Python数据分析库pandas基本操作
Python数据分析库pandas基本操作2017年02月20日 17:09:06 birdlove1987 阅读数:22631 标签: python 数据分析 pandas 更多 个人分类: Pyt ...
- Python数据分析之pandas基本数据结构:Series、DataFrame
1引言 本文总结Pandas中两种常用的数据类型: (1)Series是一种一维的带标签数组对象. (2)DataFrame,二维,Series容器 2 Series数组 2.1 Series数组构成 ...
- Python 数据分析:Pandas 缺省值的判断
Python 数据分析:Pandas 缺省值的判断 背景 我们从数据库中取出数据存入 Pandas None 转换成 NaN 或 NaT.但是,我们将 Pandas 数据写入数据库时又需要转换成 No ...
- 利用python进行数据分析之pandas入门
转自https://zhuanlan.zhihu.com/p/26100976 目录: 5.1 pandas 的数据结构介绍5.1.1 Series5.1.2 DataFrame5.1.3索引对象5. ...
- Python数据分析之pandas学习
Python中的pandas模块进行数据分析. 接下来pandas介绍中将学习到如下8块内容:1.数据结构简介:DataFrame和Series2.数据索引index3.利用pandas查询数据4.利 ...
- python数据分析之pandas数据选取:df[] df.loc[] df.iloc[] df.ix[] df.at[] df.iat[]
1 引言 Pandas是作为Python数据分析著名的工具包,提供了多种数据选取的方法,方便实用.本文主要介绍Pandas的几种数据选取的方法. Pandas中,数据主要保存为Dataframe和Se ...
- Python数据分析之pandas
Python中的pandas模块进行数据分析. 接下来pandas介绍中将学习到如下8块内容:1.数据结构简介:DataFrame和Series2.数据索引index3.利用pandas查询数据4.利 ...
- Python数据分析之Pandas操作大全
从头到尾都是手码的,文中的所有示例也都是在Pycharm中运行过的,自己整理笔记的最大好处在于可以按照自己的思路来构建矿建,等到将来在需要的时候能够以最快的速度看懂并应用=_= 注:为方便表述,本章设 ...
随机推荐
- 最大流Dinic算法
嘿嘿嘿,时隔不久又见到了DInic,再次回顾一下吧 不过这次我倒是不想深究,而是想多做一些题,因为这几次比赛下来,算法不是重点,重点是题目如何转化,算法如何应用,这也是比赛为什么让你带着板子的原因吧, ...
- unigui回车代替TAB
unigui回车代替TAB 在业务系统中常常使用回车键(Enter)替代Tab键完成焦点跳转,在uniGUI下,可以不用代码,直接使用TUniForm的NavigateKeys进行设置: 其中Next ...
- delphi怎么做桌面滚动文字?
就是在桌面显示从TXT读取出来的字,并限制在1个框内移动(就是从框左边出现往右边移动并从框边消失)我用HDC+textout只是读取字显示到桌面,不知道桌面移动哪位大侠指点下啊,或用其他方法,最好有详 ...
- DELPHI获取宽带IP
DELPHI获取宽带IP DELPHI获取宽带IP procedure TForm1.Button1Click(Sender: TObject);varurl: string;beginurl : ...
- [leetcode 14]Longest Common Prfix
1 题目: Write a function to find the longest common prefix string amongst an array of strings. Hide Ta ...
- Linux Buffer/Cache 的区别
以前经常使用free -h命令来查看当前操作系统的内存使用情况,同时也注意过返回信息中有一列是buff/cache,来公司之前,面试官还问过我这两个的区别,当时没有回答出来,现在特意回顾记录下: ...
- 安装使用Entity Framework Power Tool Bate4 (Code First)从已建好的数据自动生成项目中的对应Model(新手贴,望各位大侠给予指点)
从开始学习使用MVC以后,同时也开始接触EF,很多原理都不是太懂,只知道安装了EF以后,点击哪里可以生成数据库对应的Model,不用再自己手写Model.这里记录的就是如何从已建立好的数据库生成项目代 ...
- C#基础复习(4) 之 浅析List、Dictionary
参考资料 [1] .netCore 源码 https://github.com/dotnet/corefx [2] <Unity 3D脚本编程 使用C#语言开发跨平台游戏>陈嘉栋著 [3] ...
- WPF 右上角带数字的按钮
效果如图所示 三种方案, 1:不改控件模版,布局实现,死开 2:改button模版,利用附加属性,附加附加属性,功能多了话,不利于拓展 3:继承button,添加依赖属性,接下来是这种 1:新建类 为 ...
- C# Winform下一个热插拔的MIS/MRP/ERP框架(简介)
Programmer普弱哥们都喜欢玩自己的框架,我也不例外. 理想中,这个框架要易于理解.易于扩展.易于维护:最重要的,易于CODING. 系统是1主体框架+N模组的多个EXE/DLL组成的,在主体框 ...