代码:
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
我查了一下,是内存不够,请问有解决方法吗?