Python笔记 #17# Pandas: Merge
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的更多相关文章
- 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笔记 #16# Pandas: Operations
10 Minutes to pandas #Stats # shift 这玩意儿有啥用??? s = pd.Series([1,5,np.nan], index=dates).shift(0) # s ...
- python笔记17
1.今日内容 迭代器(3*) 生成器(4*) 装饰器(5*) 项目结构 logging模块 2.内容回顾 & 作业 2.1 内容回顾 2.1.1 函数(内置/自定义) 基本函数结构 def f ...
- golang学习笔记17 爬虫技术路线图,python,java,nodejs,go语言,scrapy主流框架介绍
golang学习笔记17 爬虫技术路线图,python,java,nodejs,go语言,scrapy主流框架介绍 go语言爬虫框架:gocolly/colly,goquery,colly,chrom ...
- Python数据分析之pandas学习
Python中的pandas模块进行数据分析. 接下来pandas介绍中将学习到如下8块内容:1.数据结构简介:DataFrame和Series2.数据索引index3.利用pandas查询数据4.利 ...
- Python数据分析库pandas基本操作
Python数据分析库pandas基本操作2017年02月20日 17:09:06 birdlove1987 阅读数:22631 标签: python 数据分析 pandas 更多 个人分类: Pyt ...
随机推荐
- <linux系统c语言生成.so文件,生成64位可执行文件,在64位系统中运行32位的可执行文件>
1.linux 系统c语言生成.o文件,---->gcc -m64 -c -fPIC test.c -o test.o2.linux 系统c语言生成.so文件,----->gcc -sha ...
- Cognos入门教程
Cognos入门教程 1. ReportStudio入门教程 ReportStudio入门教程(http://blog.csdn.net/column/details/ygy-reportstudio ...
- Oracle类型number与PG类型numeric对比和转换策略
Oracle 11g number 任意精度数字类型 http://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT3 ...
- Synergy 多系统共享鼠标键盘 Windows 和 Mac 完全配置教程
公司终于配上了双主机双系统双屏幕,编码是爽了,但是桌上的键盘有多了一套,有没有什么软件能够在不同的电脑之间共享键盘和鼠标呢?后来发下了Synergy这款软件.不仅免费而且开源(支持下). 让办公桌上的 ...
- jhipser微服务架构介绍
内容提要 本文涉及以下内容: 微服务架构介绍 spring cloud介绍 jhipster架构介绍 微服务架构介绍 微服务概念 微服务和SOA很相似,都是按照业务功能把系统拆分成一个一个的服务.比如 ...
- 【BZOJ3772】精神污染 DFS序+主席树
[BZOJ3772]精神污染 Description 兵库县位于日本列岛的中央位置,北临日本海,南面濑户内海直通太平洋,中央部位是森林和山地,与拥有关西机场的大阪府比邻而居,是关西地区面积最大的县,是 ...
- 310实验室OTL问题
1.首先是下载OTL文件包,网址是:github.com/O-T-L,可以直接点击网页上的下载链接,也可以使用unlix命令,git clone https://github.com/O-T-L/OT ...
- 01.MyBatis入门
MyBatis入参考文档:http://mybatis.org/mybatis-3/zh/ 1.使用MyBatis前的准备 1.增加Maven依赖 <dependency> &l ...
- 170725、Kafka原理与技术
本文转载自:http://www.linkedkeeper.com/detail/blog.action?bid=1016 Kafka的基本介绍 Kafka最初由Linkedin公司开发,是一个分布式 ...
- JS生成GUID方法
function GUID() { this.date = new Date(); /* 判断是否初始化过,如果初始化过以下代码,则以下代码将不再执行,实际中只执行一次 */ if (typeof t ...