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 ...
随机推荐
- Android编译系统(Android.mk文件详解)
[Android-NDK(Native Development Kit) docs文档] NDK提供了一系列的工具,帮助开发者快速开发C(或C++)的动态库,并能自动将so和java应用一起打包成a ...
- php面向对象的简单总结 $this $parent self
面向对象涉及到的比较多,大概总结整理一下php的属性.对象,以及访问方式$this $parent self 的使用场景. 1. PHP类属性定义和访问方式: 1 <?php 2 clas ...
- 深刻理解 React (一) ——JSX和虚拟DOM
版权声明:本文由左明原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/155 来源:腾云阁 https://www.qclou ...
- 【BZOJ4423】[AMPPZ2013]Bytehattan 对偶图+并查集
[BZOJ4423][AMPPZ2013]Bytehattan Description 比特哈顿镇有n*n个格点,形成了一个网格图.一开始整张图是完整的.有k次操作,每次会删掉图中的一条边(u,v), ...
- 电力项目十八--DOM对象的ajax
Ajax操作的核心对象:xmlreq = new XMLHttpRequest(); 第一步:在dictionaryIndex.jsp中添加: <script type="text/j ...
- Oracle性能优化之oracle中常见的执行计划及其简单解释
一.访问表执行计划 1.table access full:全表扫描.它会访问表中的每一条记录(读取高水位线以内的每一个数据块). 2.table access by user rowid:输入源ro ...
- Servlet + JSP 时代
Spring,Django,Rails,Express这些框架技术的出现都是为了解决什么问题,现在这些框架都应用在哪些方面? - 知乎 https://www.zhihu.com/question/2 ...
- docker 2375 vulnerability and self-signatuer certifications
Docker暴露2375端口,引起安全漏洞 今天有小伙伴发现Docker暴露出2375端口,引起了安全漏洞.我现在给大家介绍整个事情的来龙去脉,并告诉小伙伴们,怎么修复这个漏洞. 为了实现集群管理,D ...
- Python的Flask框架应用调用Redis队列数据的方法
转自:http://www.jb51.net/article/86021.htm 任务异步化 打开浏览器,输入地址,按下回车,打开了页面.于是一个HTTP请求(request)就由客户端发送到服务器, ...
- R-CNN论文详解 - CSDN博客
废话不多说,上车吧,少年 paper链接:Rich feature hierarchies for accurate object detection and semantic segmentatio ...