我有两只熊猫数据框
客户名称Dataframe:Name
ID Name
9967 Tasia Aldrich
5154 Tinisha Balcom
9780 Lonna Braga
5101 Violette Arneson
7074 Oralee Schertz
4324 Tempie Bristol
7270 Margarita Evens
2087 Jon Woodham
1301 Linwood Wollman
5897 Salvatore Oatis
等等
客户产品购买数据框:购买
ID Product
1094 Audio Equipment
5337 Cameras and Camera Equipment
3035 Car Electronics and GPS
7865 Computer Accessories
2126 Desktop Computers and Monitors
8823 Laptops and Notebooks
4987 Lighting Equipment
7920 Smartphones and Mobile Devices
5801 Tablets and E-Readers
8242 Televisions and Television Services
等等
现在两个数据帧都包含大约1200万条记录,我想根据它们的ID合并它们。我尝试使用传统的操作:
mergeDF=name.merge(purchase,'left','ID')
完全融合花了140分钟。有没有其他方法可以优化这个?你知道吗
第二部分:
我还尝试在新合并的数据帧中创建一个名为“key”的列,该列的定义如下:
mergedDF['key']=mergedDF.apply(lambda x: x.ID+'&'+x.Product,axis=1)
又得花很多时间。有什么建议吗? 我是python新手,所以任何建议都会有帮助。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐