10 Minutes to pandas

Concat

df = pd.DataFrame(np.random.randn(10, 4))
print(df)
# break it into pieces
pieces = [df[:3], df[3:7], df[7:]]
print(pd.concat(pieces))
# 0 1 2 3
# 0 0.879526 -1.417311 -1.309299 0.287933
# 1 -1.194092 1.237536 -0.375177 -0.622846
# 2 1.449524 1.732103 1.866323 0.327194
# 3 -0.028595 1.047751 0.629286 -0.611354
# 4 -1.237406 0.878287 1.407587 -1.637072
# 5 0.536248 1.172208 0.405543 0.245162
# 6 0.166374 1.185840 0.132388 -0.832135
# 7 0.750722 -1.188307 1.306327 1.564907
# 8 -0.755132 -1.538270 -0.173119 1.341313
# 9 -0.572171 1.808220 0.688190 -0.672612
# 0 1 2 3
# 0 0.879526 -1.417311 -1.309299 0.287933
# 1 -1.194092 1.237536 -0.375177 -0.622846
# 2 1.449524 1.732103 1.866323 0.327194
# 3 -0.028595 1.047751 0.629286 -0.611354
# 4 -1.237406 0.878287 1.407587 -1.637072
# 5 0.536248 1.172208 0.405543 0.245162
# 6 0.166374 1.185840 0.132388 -0.832135
# 7 0.750722 -1.188307 1.306327 1.564907
# 8 -0.755132 -1.538270 -0.173119 1.341313
# 9 -0.572171 1.808220 0.688190 -0.672612

Join

类似 sql 里的 join (联表)

left = pd.DataFrame({'key': ['foo', 'foo'], 'lval': [1, 2]})
right = pd.DataFrame({'key': ['foo', 'foo'], 'rval': [4, 5]})
print(left)
print(right)
print(pd.merge(left, right, on='key'))
# key lval
# 0 foo 1
# 1 foo 2
# key rval
# 0 foo 4
# 1 foo 5
# key lval rval
# 0 foo 1 4
# 1 foo 1 5
# 2 foo 2 4
# 3 foo 2 5

Merge

df = pd.DataFrame(np.random.randn(8, 4), columns=['A','B','C','D'])
print(df)
s = df.iloc[3]
print(s)
df.append(s, ignore_index=True)
print(df)
print(df.append(s, ignore_index=True))
# A B C D
# 0 -1.744799 -0.745689 -0.066827 -0.993191
# 1 0.843984 0.902578 0.845040 1.336861
# 2 0.865214 1.151313 0.277192 -0.711557
# 3 0.917065 -0.948935 0.110977 0.047466
# 4 -1.309586 0.539592 1.956684 -0.117199
# 5 -0.431144 0.884499 -0.828626 -0.506894
# 6 -1.263993 -0.826366 1.426688 -0.434647
# 7 -0.567870 -0.086037 2.166162 -0.396294
# /
# A 0.917065
# B -0.948935
# C 0.110977
# D 0.047466
# Name: 3, dtype: float64
# /
# A B C D
# 0 -1.744799 -0.745689 -0.066827 -0.993191
# 1 0.843984 0.902578 0.845040 1.336861
# 2 0.865214 1.151313 0.277192 -0.711557
# 3 0.917065 -0.948935 0.110977 0.047466
# 4 -1.309586 0.539592 1.956684 -0.117199
# 5 -0.431144 0.884499 -0.828626 -0.506894
# 6 -1.263993 -0.826366 1.426688 -0.434647
# 7 -0.567870 -0.086037 2.166162 -0.396294
# /
# A B C D
# 0 0.673341 0.211039 0.370737 -0.533311
# 1 -0.860026 -0.850189 -0.101193 -0.208695
# 2 1.684126 0.057633 0.775963 0.571528
# 3 0.340264 -1.576842 1.251407 1.703995
# 4 0.201961 -0.016234 -1.077373 0.477445
# 5 -0.096186 -0.766024 0.702740 -0.580853
# 6 0.941851 1.474317 -0.065384 -0.779173
# 7 -0.556754 -0.535569 -0.353260 -0.839585
# 8 0.340264 -1.576842 1.251407 1.703995

Python笔记 #17# Pandas: Merge的更多相关文章

  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笔记 #16# Pandas: Operations

    10 Minutes to pandas #Stats # shift 这玩意儿有啥用??? s = pd.Series([1,5,np.nan], index=dates).shift(0) # s ...

  6. python笔记17

    1.今日内容 迭代器(3*) 生成器(4*) 装饰器(5*) 项目结构 logging模块 2.内容回顾 & 作业 2.1 内容回顾 2.1.1 函数(内置/自定义) 基本函数结构 def f ...

  7. golang学习笔记17 爬虫技术路线图,python,java,nodejs,go语言,scrapy主流框架介绍

    golang学习笔记17 爬虫技术路线图,python,java,nodejs,go语言,scrapy主流框架介绍 go语言爬虫框架:gocolly/colly,goquery,colly,chrom ...

  8. Python数据分析之pandas学习

    Python中的pandas模块进行数据分析. 接下来pandas介绍中将学习到如下8块内容:1.数据结构简介:DataFrame和Series2.数据索引index3.利用pandas查询数据4.利 ...

  9. Python数据分析库pandas基本操作

    Python数据分析库pandas基本操作2017年02月20日 17:09:06 birdlove1987 阅读数:22631 标签: python 数据分析 pandas 更多 个人分类: Pyt ...

随机推荐

  1. web 前端规范实例

    <!DOCTYPE html> <html> <head> <title>tmall</title> <!-- 为了被搜索引擎作为流量 ...

  2. iOS性能调优系列(全)

    总结: 三类工具 基础工具 (NSLog的方式记录运行时间.) 性能工具.检测各个部分的性能表现,找出性能瓶颈 内存工具.检查内存正确性和内存使用效率 性能工具: 可以衡量CPU的使用,时间的消耗,电 ...

  3. django实现瀑布流、组合搜索、阶梯评论、验证码

    django实现图片瀑布流布局 我们在一些图片网站上经常会看到,满屏都是图片,而且图片都大小不一,却可以按空间排列.默认一个div是占用一行,当想把div里的图片并排显示的时候,只能使用float属性 ...

  4. TP框架控制器的空操作

    在浏览器中输入tp框架入口文件的地址,如图 要注意,localhost/后面跟的是www的下一级,tp文件的上一级,因为我直接把tp文件做成了www目录的下一级,所以我写的地址localhost后面跟 ...

  5. MySql学习—— 查询性能优化 深入理解MySql如何执行查询

    本篇深入了解查询优化和服务器的内部机制,了解MySql如何执行特定查询,从中也可以知道如何更改查询执行计划,当我们深入理解MySql如何真正地执行查询,明白高效和低效的真正含义,在实际应用中就能扬长避 ...

  6. Jquery跨域Ajax取值

    HTML: $.ajax({ type: "get", async: false, url: "http://www.xxxxxx.com/otherLogin/chec ...

  7. LNMP一键安装包phpMyAdmin无法正常登录,提示:您的Session已过期,请再次登录。

    找到文件: /usr/local/php/etc/php.ini 搜索: session.auto_start = 0 修改为 session.auto_start = 1 保存即可!

  8. Thinkphp3.2 PHPexcel 导出

    1 下载phpexecl  放入到tp里边. 路径如下:项目根目录\ThinkPHP\Library\Org\Util 2  PHP 代码部分 封装一个方法 private function getE ...

  9. CodeForces - 459E Pashmak and Graph[贪心优化dp]

    E. Pashmak and Graph time limit per test 1 second memory limit per test 256 megabytes input standard ...

  10. C++ 初始化函数的实现

    http://www.cppblog.com/xlshcn/archive/2007/11/21/37088.aspx