Python笔记 #16# Pandas: Operations
#Stats
# shift 这玩意儿有啥用???
s = pd.Series([1,5,np.nan], index=dates).shift(0)
# s1 = pd.Series([1,5,np.nan], index=dates).shift(1)
# s2 = pd.Series([1,5,np.nan], index=dates).shift(2)
# print(s)
# print(s1)
# print(s2)
# 2018-01-16 1.0
# 2018-01-17 5.0
# 2018-01-18 NaN
# Freq: D, dtype: float64
# 2018-01-16 NaN
# 2018-01-17 1.0
# 2018-01-18 5.0
# Freq: D, dtype: float64
# 2018-01-16 NaN
# 2018-01-17 NaN
# 2018-01-18 1.0
# Freq: D, dtype: float64 # print(df)
# print(df.sub(s, axis='index')) # "Wise subtraction"
# A B C D
# 2018-01-16 -1.809723 0.342129 2.048727 0.995959
# 2018-01-17 0.871955 1.960730 0.368855 0.459528
# 2018-01-18 -0.483717 0.031247 0.619609 -0.712104
# A B C D
# 2018-01-16 -2.809723 -0.657871 1.048727 -0.004041
# 2018-01-17 -4.128045 -3.039270 -4.631145 -4.540472
# 2018-01-18 NaN NaN NaN NaN
/
# Applying functions to the data
# print(df)
# print(df.apply(np.cumsum)) # 应用 numpy 的函数 cumsum 对每列累计求和
# A B C D
# 2018-01-16 1.516139 0.501701 0.624571 -1.270804
# 2018-01-17 -0.223673 -0.092153 0.782620 -2.073206
# 2018-01-18 0.844318 -1.180269 0.994821 -1.372318
# A B C D
# 2018-01-16 1.516139 0.501701 0.624571 -1.270804
# 2018-01-17 1.292466 0.409548 1.407191 -3.344010
# 2018-01-18 2.136784 -0.770721 2.402013 -4.716328
/
# Histogramming(直方图化) ps:就是把每个值出现的次数统计出来
# s = pd.Series(np.random.randint(0, 7, size=10))
# print(s)
# print(s.value_counts())
# 0 1
# 1 4
# 2 6
# 3 2
# 4 4
# 5 2
# 6 3
# 7 2
# 8 1
# 9 5
# dtype: int32
# 2 3
# 4 2
# 1 2
# 6 1
# 5 1
# 3 1
# dtype: int64
/
# String Methods
# s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
# print(s.str.lower())
# 0 a
# 1 b
# 2 c
# 3 aaba
# 4 baca
# 5 NaN
# 6 caba
# 7 dog
# 8 cat
# dtype: object
Python笔记 #16# Pandas: Operations的更多相关文章
- Python笔记 #15# Pandas: Missing Data
10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...
- Python笔记 #14# Pandas: Selection
10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...
- Python笔记 #13# Pandas: Viewing Data
感觉很详细:数据分析:pandas 基础 import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...
- Python笔记 #18# Pandas: Grouping
10 Minutes to pandas 引 By “group by” we are referring to a process involving one or more of the foll ...
- Python笔记 #17# Pandas: Merge
10 Minutes to pandas Concat df = pd.DataFrame(np.random.randn(10, 4)) print(df) # break it into piec ...
- python笔记16
1.今日内容 模块基础知识 time/datetime json/picle shutil logging 其他 2.内容回顾和补充 2.1模块(类库) 内置 第三方 自定义 面试题: 列举常用内置模 ...
- 学习笔记之pandas
Python Data Analysis Library — pandas: Python Data Analysis Library https://pandas.pydata.org/ panda ...
- 利用Python进行数据分析-Pandas(第一部分)
利用Python进行数据分析-Pandas: 在Pandas库中最重要的两个数据类型,分别是Series和DataFrame.如下的内容主要围绕这两个方面展开叙述! 在进行数据分析时,我们知道有两个基 ...
- 【Python实战】Pandas:让你像写SQL一样做数据分析(一)
1. 引言 Pandas是一个开源的Python数据分析库.Pandas把结构化数据分为了三类: Series,1维序列,可视作为没有column名的.只有一个column的DataFrame: Da ...
随机推荐
- 电脑CPU的发展史(转)
Intel于1971年发售了自己的第一款4位微处理器,设计与ROM 4001,RAM 4002和移位寄存器4003配合工作.其中4004自身负责运算,其它部分则是使CPU正常工作的重要组成.大部分40 ...
- php学习六:字符串
前言:越来越觉得php的强大之处了,不紧是数组,在字符串方面也可以看出它的优势,第一:方法多,集合了js,c,c#等多门语言的方法:第二:有许多方法是其他语言不具备的,如他的模糊比较,就是其他语言所没 ...
- Androidの共享登录之方案研究
由于最近公司提到了一个需求是,一个应用登录成功了,另一个自动登录. 绞尽脑汁想了好几天,看起来很容易但是想深点就漏洞百出,有的时候代码都写完了测试都成功了突然发现给一个假设就完全失效. 先前几个同事之 ...
- Java中迭代器实现的原理
一. 引言 迭代这个名词对于熟悉Java的人来说绝对不陌生.我们常常使用JDK提供的迭代接口进行java collection的遍历: Iterator it = list.iterator();wh ...
- 国内linux 镜像
北京理工大学开源软件镜像服务mirrors.ustc.edu.cn 开源中国社区软件镜像下载资源库mirrors.oss.org.cn 阿里云开源镜像站mirrors.aliyun.com<ig ...
- Android 菜单动态变化【添加或去除】
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android: ...
- Minix2.0内核源代码的组织结构
Minix2.0操作系统的源代码由两个目录组成:include/目录和src/目录 include/目录包含了操作系统所有的头文件(即.h文件) src/目录下包含了操作系统所有的源文件(.c或.s文 ...
- 根据Uri获取图片绝对路径,解决Android4.4以上版本Uri转换
转:http://blog.csdn.net/q445697127/article/details/40537945 /** * 根据Uri获取图片绝对路径,解决Android4.4以上版本Uri转换 ...
- Intellij IDEA同时打开多个项目
extends:http://www.kaifazhe.me/java/99.html 使用eclipse习惯的同学知道是可以同时多个项目查看的,只需要import就可以了,但Intellij IDE ...
- lambda 缩写推演