在pandas中,concat, merge, join的使用方法可以参考以下资料:
http://blog.csdn.net/stevenkwong/article/details/52528616
主要讲下笛卡尔积:

import pandas as pd
from pandas import DataFrame
df1=DataFrame({'a':[1,2,3], 'b':[4,5,6], 'key':[0,0,0]})
df2=DataFrame({'c':[3,2,1], 'd':[6,5,4], 'key':[0,0,0]})
data = pd.merge(df1, df2, on='key')

这里merge默认为内连接。

df1:

   a  b  key
0 1 4 0
1 2 5 0
2 3 6 0

  

df2:

   c  d  key
0 3 6 0
1 2 5 0
2 1 4 0

  

data:

   a  b  key  c  d
0 1 4 0 3 6
1 1 4 0 2 5
2 1 4 0 1 4
3 2 5 0 3 6
4 2 5 0 2 5
5 2 5 0 1 4
6 3 6 0 3 6
7 3 6 0 2 5
8 3 6 0 1 4

  

由此可知,当两个表连接时,有相同的key值就产生积。

如果,需要进行merge的次数过多时,每次都产生笛卡尔积,最终就会产生内存爆炸的现象。

所以,在merge时,一定要避免相同的key值,可以分批次merge,最后再concat。
---------------------

原文:https://blog.csdn.net/yj1556492839/article/details/79529186

python dataframe 在merge时 产生笛卡尔积的更多相关文章

  1. (原)怎样解决python dataframe loc,iloc循环处理速度很慢的问题

    怎样解决python dataframe loc,iloc循环处理速度很慢的问题 1.问题说明 最近用DataFrame做大数据 处理,发现处理速度特别慢,追究原因,发现是循环处理时,loc,iloc ...

  2. Python dataframe中如何使y列按x列进行统计?

    如图:busy=0 or 1,求出busy=1时los的平均,同样对busy=0时也求出los的平均 Python dataframe中如何使y列按x列进行统计? >> python这个答 ...

  3. 怎样解决python dataframe loc,iloc循环处理速度很慢的问题

    怎样解决python dataframe loc,iloc循环处理速度很慢的问题 1.问题说明 最近用DataFrame做大数据 处理,发现处理速度特别慢,追究原因,发现是循环处理时,loc,iloc ...

  4. git有merge时如何删除分支

    不小心增加了一个分支,并且有了merge,如何删除掉? 具有merge时不能切换分支 可以利用git stash命令 git rm controllers/InterfaceController.ph ...

  5. python在读取文件时出现 'gbk' codec can't decode byte 0x89 in position 68: illegal multibyte sequence

    python在读取文件时出现“UnicodeDecodeError:'gbk' codec can't decode byte 0x89 in position 68: illegal multiby ...

  6. [Spark][Python][DataFrame][RDD]DataFrame中抽取RDD例子

    [Spark][Python][DataFrame][RDD]DataFrame中抽取RDD例子 sqlContext = HiveContext(sc) peopleDF = sqlContext. ...

  7. [Spark][Python][DataFrame][RDD]从DataFrame得到RDD的例子

    [Spark][Python][DataFrame][RDD]从DataFrame得到RDD的例子 $ hdfs dfs -cat people.json {"name":&quo ...

  8. [Spark][Python][DataFrame][Write]DataFrame写入的例子

    [Spark][Python][DataFrame][Write]DataFrame写入的例子 $ hdfs dfs -cat people.json {"name":" ...

  9. [Spark][Python][DataFrame][SQL]Spark对DataFrame直接执行SQL处理的例子

    [Spark][Python][DataFrame][SQL]Spark对DataFrame直接执行SQL处理的例子 $cat people.json {"name":" ...

随机推荐

  1. MySQL 动态sql语句运行 用时间做表名

    1. 描写叙述 在使用数据的时候,我时候我们须要非常多数据库,并且想用时间来做表名以区分.可是MySQL在存储过程中不支持使用变量名来做表名或者列名. 比方,有一个表我们想以"2015-07 ...

  2. [Node.js] Level 2 new. Event

    Chat Emitter We're going to create a custom chat EventEmitter. Create a new EventEmitter object and ...

  3. JAVA中AES对称加密和解密

    AES对称加密和解密 package demo.security; import java.io.IOException; import java.io.UnsupportedEncodingExce ...

  4. 二叉查找树实现实例(C语言)

    /* search_tree.h */ #ifndef _SEARCH_TREE_H #define _SEARCH_TREE_H struct tree_node; typedef struct t ...

  5. Simple example

    This is a simple example showing a small window. Yet we can do a lot with this window. We can resize ...

  6. Win10怎么设置点击任务栏上文件夹图标直接打开“我的电脑”?

    我们都知道Win10任务栏上的文件夹图标可以打开文件资源管理器,但是点击这个图标后打开的位置却是不固定的,有可能是库文件夹,也有可能是其他常用的位置.怎么设置点击这个图标后直接打开"此电脑& ...

  7. WebApi 数据保护操作未成功。这可能是由于未为当前线程的用户上下文加载用户配置文件导致的。当线程执行模拟时,可能会出现此情况。","ExceptionType":"System.Security.Cryptography.CryptographicException","StackTrace

    在调用System.Security.Cryptography.ProtectedData.Protect方法来保护私密信息时,IIS可能会报以下错误:CryptographicException: ...

  8. Flash actionscript3.0 多个setTimeout之间会顺序执行 单线程执行 无法中止

    做了一个试验,测试能否在另外的setTimeout中中断其他代码的执行.结果表明,是不可能的,Actionscript会按顺序,逐个逐个的执行. private var index:int; priv ...

  9. x-code的使用技巧心得

    xcode是苹果开发的一款图形化,而且用户交互很好的开发软件开发工具. 它支持 C语言 o-bjiect语言 c++ 等多种语言的开发.功能强大,俗话说的好,工欲善其事,必先利其器,以下将描写叙述一下 ...

  10. [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口(转)

    转自:[CXF REST标准实战系列] 二.Spring4.0 整合 CXF3.0,实现测试接口 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现W ...