10 Minutes to pandas

#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的更多相关文章

  1. Python笔记 #15# Pandas: Missing Data

    10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...

  2. Python笔记 #14# Pandas: Selection

    10 Minutes to pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...

  3. Python笔记 #13# Pandas: Viewing Data

    感觉很详细:数据分析:pandas 基础 import pandas as pd import numpy as np import matplotlib.pyplot as plt dates = ...

  4. Python笔记 #18# Pandas: Grouping

    10 Minutes to pandas 引 By “group by” we are referring to a process involving one or more of the foll ...

  5. Python笔记 #17# Pandas: Merge

    10 Minutes to pandas Concat df = pd.DataFrame(np.random.randn(10, 4)) print(df) # break it into piec ...

  6. python笔记16

    1.今日内容 模块基础知识 time/datetime json/picle shutil logging 其他 2.内容回顾和补充 2.1模块(类库) 内置 第三方 自定义 面试题: 列举常用内置模 ...

  7. 学习笔记之pandas

    Python Data Analysis Library — pandas: Python Data Analysis Library https://pandas.pydata.org/ panda ...

  8. 利用Python进行数据分析-Pandas(第一部分)

    利用Python进行数据分析-Pandas: 在Pandas库中最重要的两个数据类型,分别是Series和DataFrame.如下的内容主要围绕这两个方面展开叙述! 在进行数据分析时,我们知道有两个基 ...

  9. 【Python实战】Pandas:让你像写SQL一样做数据分析(一)

    1. 引言 Pandas是一个开源的Python数据分析库.Pandas把结构化数据分为了三类: Series,1维序列,可视作为没有column名的.只有一个column的DataFrame: Da ...

随机推荐

  1. 用示例详解php连接数据库操作

    首先数据库mydb有三个表: 1  info表 2  users表 3  sname表 首先先做一个登录主页面 login_1.php <!DOCTYPE html PUBLIC "- ...

  2. 在ubuntu14.04上漏洞环境vulndocker的DOCKER搭建

    一.下载git包以及安装: git clone https://github.com/leveryd/vulndocker.git cd vulndocker apt-get install uwsg ...

  3. {sharepoint}提升 SharePoint 代码执行权限

    提升 SharePoint 代码执行权限 关于如何提升 SharePoint 代码执行权限及相关知识介绍的文章我们园子里有很多, 这里给出其中两篇文章的链接,就不再啰嗦了. http://www.cn ...

  4. windows 下,go语言 交叉编译

    http://bbs.csdn.net/topics/390601048 参考上面的操作

  5. 纯HTML自动刷新页面或重定向(http-equiv属性的refresh)

    refresh 属性值  --  刷新与跳转(重定向)页面 refresh出现在http-equiv属性中,使用content属性表示刷新或跳转的开始时间与跳转的网址 refresh示例一:5秒之后刷 ...

  6. mysql GROUP_CONCAT 用法

    group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符']) 基本查询 mysql> select * f ...

  7. postgresql----INSERT

    INSERT即向表中写入数据,每条INSERT语句可以写入一条数据,也可以写入多条数据.另外还可以将其他的查询结果集用在INSERT中,将查询结果写入表中. 测试表 test)); CREATE TA ...

  8. SVN 配置和使用

    SVN使用环境 使用SVN管理源代码,必须有2套环境 服务器 用来存储客户端上传的源码 一般都是在Windows环境下安装Visual SVN Server 客户端 用来提交.回退.修改.下载等操作 ...

  9. 使用Dataset构建数据到lgb中

    训练数据要放到Dataset中供lgb使用,构建数据如下: import lightgbm as lgb import numpy as np # 训练数据,500个样本,10个维度 train_da ...

  10. 用 chown 和 chmod 修改目录所属用户及权限

    1.修改 tmp 目录所属用户为 root,用户组为 root chown -R root:root /tmp12.修改 tmp 目录为可写权限 chmod -R 777 /tmp