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. Spring事务核心接口

  2. sql查询数据库中所有表名

    查询数据库里所有表名和字段名的语句SQL 查询所有表名:SELECT NAME FROM SYSOBJECTS WHERE TYPE='U'SELECT * FROM INFORMATION_SCHE ...

  3. ASP.NET 4.0尚未在Web服务器注册 解决

    http://www.cnblogs.com/lvxiouzi/p/3511446.html 安装asp.net 4.0.30319.0版本 命令: %windir%\Microsoft.NET\Fr ...

  4. java基础---->多个排序的拓展

    根据一些特定的规则,我们可以利用java的反射机制做到很有趣的封装. java的排序封装 一.定义一些comparator AmountComparatorAsc:amount升序 package c ...

  5. c# 对数据库的操作

    1.首先需要引用 using System.Data.SqlClient; 2.创建连接 SqlConnection connection = new SqlConnection(); connect ...

  6. go练习3 --map的操作

    func T2_1() {     // 键值string , 值 int 类型     m1 := map[string]int{}     //添加一个元素     m1["str1&q ...

  7. Python - 3.6 学习三

    面向对象编程 面向对象编程 Object Oriented Programming 简称 OOP,是一种程序设计思想.OOP把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数. 面向过程的程 ...

  8. nginx负载均衡模块

    1.upstream 模块 upstream backend { server backend1.example.com weight=5 max_fails=10 fail_timeout=10s; ...

  9. G1垃圾收集器入门-原创译文

    G1垃圾收集器入门-原创译文 原文地址 Getting Started with the G1 Garbage Collector 概览 目的 本文介绍了如何使用G1垃圾收集器以及如何与Hotspot ...

  10. Windows使用filezilla搭建FTP服务器

    参考:https://segmentfault.com/a/1190000009033181 下载软件https://filezilla-project.org/ 安装过程不详述,默认安装即可 启动软 ...