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. poj_1743 后缀数组

    题目大意 给定一串数字,长度为N.定义数字中的某个连续的子串为一个"theme",只要子串满足: (1)长度 >= 5 (2)和该子串相同或者该子串的“变种串”在整串数字中出 ...

  2. 【WebService】Stax的基本操作基于游标

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <book ...

  3. Zabbix漏洞汇总

    一.zabbix: zabbix是监控是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让 ...

  4. 【BZOJ1001】[BeiJing2006]狼抓兔子 对偶图最短路

    [BZOJ1001][BeiJing2006]狼抓兔子 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子 ...

  5. c# WinForm 边框阴影窗体

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. 不同linux下两网卡绑定方法

    记得原来在做性能测试时,为了提高网络吞吐率.必须将两个网卡绑定一起工作.绑定方法如下: 一.CentOS 配置   1.编辑虚拟网络接口配置文件,指定网卡IP: # vi /etc/sysconfig ...

  7. Android 让GridView的高度为Wrap_content根据内容自适应高度

    From:http://www.jayway.com/2012/10/04/how-to-make-the-height-of-a-gridview-wrap-its-content/ 如果把Grid ...

  8. HDU Humble Numbers

    Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...

  9. Linux系统下JDK安装配置(转载)

    转载出处:http://www.cnblogs.com/xuliangxing/p/7066913.html 本文主要介绍的是如何是Linux环境下安装JDK的,因为Linux环境下,很多时候也离不开 ...

  10. pta 习题集5-6 堆栈操作合法性

    假设以S和X分别表示入栈和出栈操作.如果根据一个仅由S和X构成的序列,对一个空堆栈进行操作,相应操作均可行(如没有出现删除时栈空)且最后状态也是栈空,则称该序列是合法的堆栈操作序列.请编写程序,输入S ...