python dataframe 在merge时 产生笛卡尔积
在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时 产生笛卡尔积的更多相关文章
- (原)怎样解决python dataframe loc,iloc循环处理速度很慢的问题
怎样解决python dataframe loc,iloc循环处理速度很慢的问题 1.问题说明 最近用DataFrame做大数据 处理,发现处理速度特别慢,追究原因,发现是循环处理时,loc,iloc ...
- Python dataframe中如何使y列按x列进行统计?
如图:busy=0 or 1,求出busy=1时los的平均,同样对busy=0时也求出los的平均 Python dataframe中如何使y列按x列进行统计? >> python这个答 ...
- 怎样解决python dataframe loc,iloc循环处理速度很慢的问题
怎样解决python dataframe loc,iloc循环处理速度很慢的问题 1.问题说明 最近用DataFrame做大数据 处理,发现处理速度特别慢,追究原因,发现是循环处理时,loc,iloc ...
- git有merge时如何删除分支
不小心增加了一个分支,并且有了merge,如何删除掉? 具有merge时不能切换分支 可以利用git stash命令 git rm controllers/InterfaceController.ph ...
- 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 ...
- [Spark][Python][DataFrame][RDD]DataFrame中抽取RDD例子
[Spark][Python][DataFrame][RDD]DataFrame中抽取RDD例子 sqlContext = HiveContext(sc) peopleDF = sqlContext. ...
- [Spark][Python][DataFrame][RDD]从DataFrame得到RDD的例子
[Spark][Python][DataFrame][RDD]从DataFrame得到RDD的例子 $ hdfs dfs -cat people.json {"name":&quo ...
- [Spark][Python][DataFrame][Write]DataFrame写入的例子
[Spark][Python][DataFrame][Write]DataFrame写入的例子 $ hdfs dfs -cat people.json {"name":" ...
- [Spark][Python][DataFrame][SQL]Spark对DataFrame直接执行SQL处理的例子
[Spark][Python][DataFrame][SQL]Spark对DataFrame直接执行SQL处理的例子 $cat people.json {"name":" ...
随机推荐
- https://leetcode-cn.com/
https://leetcode-cn.com/ 码,马不停蹄,码不停题 英文版:https://leetcode.com/
- 调整WebLogic的时间
控制台显示的时区为GMT,于是考虑调整WebLogic的时区,查询WebLogic的相关参数后,初步的调整方式为:修改相关域下的bin目录中的startWebLogic.cmd脚本.添加"- ...
- C#.NET常见问题(FAQ)-TabControl如何隐藏和显示页面
如果需要显示某个页面,则让他的Parent就是TabControl的控件名称,如果要隐藏,则等于null private void ToolStripMenuItemTeachPanelBa ...
- windows server 2012 IE增强的安全配置如何关闭
http://jingyan.baidu.com/article/6181c3e076ac0b152ff15354.html 打开左下角的 服务端 关闭这个就可以了
- nginx+tomcat+redis完成session共享(转载)
转载:http://blog.csdn.net/grhlove123/article/details/48047735 tomcat7下基于redis的session共享所需jar包: http:// ...
- Java实现根据输入的日期以及天数,获取此日期之后的天数的工作日
public static void main(String[] args) { List<String> list = new ArrayList<String>();//节 ...
- java web下串口通讯
最近在做java串口通讯,主要是用个人电脑通过串口从RS485读取数据,并通过crc循环冗余校验,把接收正确的数据解析,插入数据库mysql,并用SSH技术把数据库数据以表格以及图表形式显示 ...
- 王立平--include在Android中的应用
一个布局中包括还有一个布局 1.在layout下定义activity_other.xml布局 2.代码中的包括例如以下: <LinearLayout xmlns:android="ht ...
- maven 将jar包添加到本地仓库
maven 如何将jar包添加到本地仓库 CreateTime--2018年4月19日12:50:50 Author:Marydon 情景描述:当项目所需的jar包,maven中央仓库中没有该j ...
- HDU 5402 Travelling Salesman Problem(棋盘染色 构造 多校啊)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5402 Problem Description Teacher Mai is in a maze wit ...