import psutil
def print_memory_usage():
process = psutil.Process(os.getpid())
memory_info = process.memory_info()
print(f"Memory usage: {memory_info.rss / 10 ** 6} MB")
return memory_info.rss / 10 ** 6
使用:
if __name__ == '__main__':
# 在你的代码中调用这个函数
a = print_memory_usage()
data_frame = pd.read_csv('123.csv')
b = print_memory_usage()
data_new = data_frame[['A', 'B']].groupby(['A']).agg({'B': 'sum'}).reset_index()
c = print_memory_usage()
print(c - b)