python pandas库基础
来源:互联网 发布:怎么申请淘宝店铺 编辑:程序博客网 时间:2024/05/01 11:55
pandas核心:Series和DataFrame分别对应一维的序列好二维的表结构
使用:
from pandas import Series,DataFrame
import pandas as pd
大部分一维数据都可以用来构造Series对象----Series包含index和values属性
例子
>s=Series([1,2,3,4,'abc'])
>s
0 1
1 2
2 3
3 4
4 abc
dtype:object
>s=Series(data=[1,2,3],index=['a','b',c])
>s
a 1
b 2
c 3
dtype:int64
>s.index
Index(['a','b','c'],dtype='object')
DataFrame是表格类型的数据结构
它含有一组有序的列(类似于 index),每列可以是不同的值类型(不像 ndarray
只能有一个 dtype)
基础语法:DataFrame(data=None,index=None,Columns=None)//index是索引,
columns是列名
例子
>data={'state':['a','b','c'],'year':[2013,2014,2015],'pop':[1,2,3]}
> data
{'state': ['a', 'b', 'c'], 'pop': [1, 2, 3], 'year': [2013, 2014, 2015]}
> df=DataFrame(data)
> df
pop state year
0 1 a 2013
1 2 b 2014
2 3 c 2015
> df=DataFrame(data,index=['one','two','three'],columns=
['year','state','pop','debt'])
> df
year state pop debt
one 2013 a 1 NaN
two 2014 b 2 NaN
three 2015 c 3 NaN //NAN表示缺失
pandas的一些统计方法:
count 非 NA 值的数量
describe 针对 Series 或 DF 的列计算汇总统计
min , max 最小值和最大值
argmin , argmax 最小值和最大值的索引位置(整数)
idxmin , idxmax 最小值和最大值的索引值
quantile 样本分位数(0 到 1)
sum 求和
mean 均值
median 中位数
mad 根据均值计算平均绝对离差
var 方差
std 标准差
skew 样本值的偏度(三阶矩)
kurt 样本值的峰度(四阶矩)
cumsum 样本值的累计和
cummin , cummax 样本值的累计最大值和累计最小值
cumprod 样本值的累计积
diff 计算一阶差分(对时间序列很有用)
pct_change 计算百分数变化
使用:
from pandas import Series,DataFrame
import pandas as pd
大部分一维数据都可以用来构造Series对象----Series包含index和values属性
例子
>s=Series([1,2,3,4,'abc'])
>s
0 1
1 2
2 3
3 4
4 abc
dtype:object
>s=Series(data=[1,2,3],index=['a','b',c])
>s
a 1
b 2
c 3
dtype:int64
>s.index
Index(['a','b','c'],dtype='object')
DataFrame是表格类型的数据结构
它含有一组有序的列(类似于 index),每列可以是不同的值类型(不像 ndarray
只能有一个 dtype)
基础语法:DataFrame(data=None,index=None,Columns=None)//index是索引,
columns是列名
例子
>data={'state':['a','b','c'],'year':[2013,2014,2015],'pop':[1,2,3]}
> data
{'state': ['a', 'b', 'c'], 'pop': [1, 2, 3], 'year': [2013, 2014, 2015]}
> df=DataFrame(data)
> df
pop state year
0 1 a 2013
1 2 b 2014
2 3 c 2015
> df=DataFrame(data,index=['one','two','three'],columns=
['year','state','pop','debt'])
> df
year state pop debt
one 2013 a 1 NaN
two 2014 b 2 NaN
three 2015 c 3 NaN //NAN表示缺失
pandas的一些统计方法:
count 非 NA 值的数量
describe 针对 Series 或 DF 的列计算汇总统计
min , max 最小值和最大值
argmin , argmax 最小值和最大值的索引位置(整数)
idxmin , idxmax 最小值和最大值的索引值
quantile 样本分位数(0 到 1)
sum 求和
mean 均值
median 中位数
mad 根据均值计算平均绝对离差
var 方差
std 标准差
skew 样本值的偏度(三阶矩)
kurt 样本值的峰度(四阶矩)
cumsum 样本值的累计和
cummin , cummax 样本值的累计最大值和累计最小值
cumprod 样本值的累计积
diff 计算一阶差分(对时间序列很有用)
pct_change 计算百分数变化
0 0
- python pandas库基础
- Python Pandas基础1
- Python pandas基础2
- python pandas基础3
- python-Pandas基础
- Python之pandas基础
- python基础之pandas
- python pandas基础
- Python基础-Pandas
- Python 数据分析-pandas 基础
- Pandas库基础操作
- Python 中的Pandas库
- Python之Pandas库
- Python 中的Pandas库
- python pandas库详解
- Python pandas库
- Python之Pandas库
- python之pandas库
- CF 589F 网络流(or贪心?)
- MySQL 复习笔记
- 成员变量和局部变量有什么区别?
- SPH算法简介3
- 关于anaconda分析的第一篇
- python pandas库基础
- Yotoc Project快速指南
- 第12章 类和动态内存分配(待补充)
- Web性能优化与Http2
- 一、OpenCV的安装
- java 中的resultset的类型
- SPH算法简介4
- Spring事务配置的五种方式
- prctl系统函数