江jh 2022-02-17 21:05 采纳率: 87.5%
浏览 98
已结题

python pandas dataframe merge报错

代码:


def merge(df1,df2,left_on='用户编号', right_on='用户编号' ,suffixes=['_1', ''],rows=500000):
    length=len(df1)
    count=length//rows+1
    df_all=[]
    print('merge_count',count)
    for i in range(count):
        print('merge',i)
        df_some=pd.DataFrame()
        if i<count-1:
            df_some=df1[i*rows:(i+1)*rows]
            
        else:
            df_some=df1[i*rows:]
            print(len(df_some))
            print('df_some',df_some)
        df_res_1 = pd.merge(df_some, df2, left_on=left_on, right_on=right_on, suffixes=suffixes)#输出到一定的值这里报错
        df_all.append(df_res_1)
                
    df_res=pd.concat(df_all, axis=0)
    print('df_res',df_res)
    return df_res

报错

输出:


merge_count 41
merge 0
merge 1
merge 2
merge 3
merge 4
merge 5
merge 6
merge 7
merge 8
merge 9
merge 10
merge 11
merge 12
merge 13
merge 14
merge 15
merge 16
merge 17
merge 18
merge 19
merge 20
merge 21
merge 22
merge 23
merge 24
merge 25
merge 26
merge 27
merge 28
merge 29
merge 30
merge 31
merge 32
merge 33
merge 34
merge 35
merge 36
Traceback (most recent call last):
  File "D:/jjh0128/guan_lian_0217_2_10_days_jjh.py", line 176, in <module>
    dfdf3 = merge(df, df3, left_on='用户编号', right_on='用户编号', suffixes=['_1', ''])
  File "D:/jjh0128/guan_lian_0217_2_10_days_jjh.py", line 45, in merge
    df_res_1 = pd.merge(df_some, df2, left_on=left_on, right_on=right_on, suffixes=suffixes)
  File "C:\Users\jjh\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\reshape\merge.py", line 89, in merge
    return op.get_result()
  File "C:\Users\jjh\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\reshape\merge.py", line 681, in get_result
    copy=self.copy,
  File "C:\Users\jjh\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\internals\concat.py", line 79, in concatenate_block_managers
    _concatenate_join_units(join_units, concat_axis, copy=copy,),
  File "C:\Users\jjh\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\internals\concat.py", line 318, in _concatenate_join_units
    for ju in join_units
  File "C:\Users\jjh\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\internals\concat.py", line 318, in <listcomp>
    for ju in join_units
  File "C:\Users\jjh\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\internals\concat.py", line 301, in get_reindexed_values
    values = algos.take_nd(values, indexer, axis=ax, fill_value=fill_value)
  File "C:\Users\jjh\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\algorithms.py", line 1732, in take_nd
    out = np.empty(out_shape, dtype=dtype)
numpy.core._exceptions.MemoryError: Unable to allocate 11.6 MiB for an array with shape (6, 253472) and data type object

Process finished with exit code 1

我查了一下,是内存不够,请问有解决方法吗?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 2月25日
    • 修改了问题 2月17日
    • 创建了问题 2月17日

    悬赏问题

    • ¥15 QTableWidget重绘程序崩溃
    • ¥15 51寻迹小车定点寻迹
    • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
    • ¥15 关于vue2中methods使用call修改this指向的问题
    • ¥15 idea自动补全键位冲突
    • ¥15 请教一下写代码,代码好难
    • ¥15 iis10中如何阻止别人网站重定向到我的网站
    • ¥15 滑块验证码移动速度不一致问题
    • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
    • ¥15 麒麟V10桌面版SP1如何配置bonding