pandas中的Series学习
来源:互联网 发布:网络运维工程师简历 编辑:程序博客网 时间:2024/05/29 04:34
具体方法参见:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html
Series 是一个一维数组结构的,可以存入任一一种python的数据类型(integers, strings, floating point numbers, Python objects, etc.)。
创建一个Series的最基本方法是:
>>> s = pd.Series(data, index=index)
程序:
# -*- coding: utf-8 -*-#-*-coding : utf-8 -*-
import numpy as np
import pandas as pd
s = pd.Series([1,2,3,np.nan,6]) #np.nan为NAN;
q =pd.Series({'a':3,'b':4,'c':5,'f':6,'e':8}) #以一字典结构为参数
print q
print "len():",len(s) #Series(s)的长度,包括NAN;注意:NAN在pandas中不是一个值是缺省值
print "shape():",np.shape(s) #矩阵形状;
print "count():",s.count() #Series的长度,不包括NAN;
print "unique():",s.unique() #出现不重复的values值;
print "value_counts():\n",s.value_counts() #同意values值得次数;
print s
print '*'*40
t = pd.Series(np.random.randn(5),index=['a','b','c','d','e'],name='something') # pd.Series([list],index=[list])//以list为参数,参数为一list;index为可选参数,
print t #若不填则默认index从0开始;若添则index长度与value长度相等
print '^'*40
m = pd.Series(5.,index=['a','b','c','d','e'])
print m
print '%'*40
a = pd.Series(np.random.random_sample(20))
print a
print a.head() #取出头n行,n为可选参数,默认n=5;
print a.tail() #取末尾n行,n为可选参数,默认n=5;
print '$'*40
print m+t #相同index的value相加,若index并非共有的则该index对应value变为NaN
print '@'*40
print s+t
结果:
a 3
b 4
c 5
e 8
f 6
dtype: int64
len(): 5
shape(): (5L,)
count(): 4
unique(): [ 1. 2. 3. nan 6.]
value_counts():
6.0 1
3.0 1
2.0 1
1.0 1
dtype: int64
0 1.0
1 2.0
2 3.0
3 NaN
4 6.0
dtype: float64
****************************************
a -0.927462
b -0.027922
c -1.569187
d -1.595163
e 0.547615
Name: something, dtype: float64
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
a 5.0
b 5.0
c 5.0
d 5.0
e 5.0
dtype: float64
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0 0.718951
1 0.826478
2 0.484672
3 0.792322
4 0.336493
5 0.764659
6 0.515082
7 0.917730
8 0.131164
9 0.358306
10 0.557721
11 0.286593
12 0.507390
13 0.877456
14 0.614322
15 0.985765
16 0.087540
17 0.336409
18 0.543998
19 0.319411
dtype: float64
0 0.718951
1 0.826478
2 0.484672
3 0.792322
4 0.336493
dtype: float64
15 0.985765
16 0.087540
17 0.336409
18 0.543998
19 0.319411
dtype: float64
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
a 4.072538
b 4.972078
c 3.430813
d 3.404837
e 5.547615
dtype: float64
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
a NaN
b NaN
c NaN
d NaN
e NaN
dtype: float64
阅读全文
0 0
- pandas中的Series学习
- pandas学习笔记-Series
- pandas数据结构Series学习
- Pandas Series
- pandas: series
- Pandas Series
- pandas-Series
- Pandas-Series
- pandas学习:series的基本用法
- 【机器学习】pandas中Series和DataFrame
- pandas&pandas学习教程&DataFrame与Series数据结构
- pandas中的两种数据类型Series和DataFrame区别
- Pandas学习:对于Series和DataFrame一些基本操作
- pandas学习:对series和dataframe进行排序
- 我的python学习笔记(4) pandas 之 Series, DataFrame
- pandas-series总结
- python pandas series
- Pandas Series操作
- 关于时间格式yyyy-mm-dd 格式在ie8返回NAN问题
- springmvc配置拦截器
- Javascript中constructor作用
- FastDFS_v5.05安装配置
- SpringBoot中配置orcale数据库连接
- pandas中的Series学习
- android 桌面设置的方法
- vue-cli环境下使用d3.js
- 快捷键
- 树的子结构
- HttpWebRequest类
- 大型项目架构演进过程及思考的点
- 关键词抽取工具-THUtag 个人使用心得
- Android 渐变色背景