Skip to main content

以不同文件格式保存数据帧时评估 pandas 性能的工具。

项目描述

Pandas 保存分析器

pandas_save_profiler帮助您评估和比较不同 pandas 读写方法的性能。

安装

pip install pandas-save-profiler

用法

加载 pandas 和要保存的数据框。

import pandas as pd
data = pd.util.testing.makeMissingDataframe()

加载pandas_save_profiler并使用它来评估 pandas 保存泡菜文件的性能:

import pandas_save_profiler
data.save_profiler('to_pickle')

输出是熊猫系列:

format                                                 pickle
writer                                              to_pickle
reader                                            read_pickle
writer_args                      {'path': '/tmp/tmppk7nkivk'}
reader_args        {'filepath_or_buffer': '/tmp/tmppk7nkivk'}
writer_time                                         0.0798338
reader_time                                         0.0294895
writer_memory                                     1.09087e+08
reader_memory                                     1.09118e+08
df_memory                                                 288
file_size                                                1122
writer_memory_h                                      109.1 MB
reader_memory_h                                      109.1 MB
df_memory_h                                         288 Bytes
file_size_h                                            1.1 kB
repeats                                                     5
reads_the_same                                           True
dtype: object

系列中的值表示:

  • 用于持久化数据帧以及写入和读取选项的格式。
  • 以秒为单位的写作和阅读时间
  • 写入和读取内存增量。
  • 内存中数据帧的大小。
  • 保存文件的大小

内存值以字节为单位,但也报告了“人性化”版本。保存和重新加载过程重复5 次并返回平均值。该标志reads_the_same指示重新加载的文件是否与原始文件完全相同或有一些差异。

比较几个写入选项,您可以在每个选项上使用该save_profiler函数并将结果组合到结果数据框中:

pd.DataFrame([
    data.save_profiler('to_csv'),
    data.save_profiler('to_pickle'),
    data.save_profiler('to_parquet'),
])

返回:

    format      writer        reader                          writer_args  \
0      csv      to_csv      read_csv  {'path_or_buf': '/tmp/tmpsedehjob'}   
1   pickle   to_pickle   read_pickle         {'path': '/tmp/tmp_vhue2q7'}   
2  parquet  to_parquet  read_parquet         {'path': '/tmp/tmp0zn8qsnk'}   

                                  reader_args  writer_time  reader_time  \
0  {'filepath_or_buffer': '/tmp/tmpsedehjob'}     0.031842     0.039830   
1  {'filepath_or_buffer': '/tmp/tmp_vhue2q7'}     0.025705     0.028469   
2                {'path': '/tmp/tmp0zn8qsnk'}     0.039009     0.052447   

   writer_memory  reader_memory  df_memory  file_size writer_memory_h  \
0    110149632.0    110599372.8        288        139        110.1 MB   
1    110813184.0    110813184.0        288       1122        110.8 MB   
2    116892467.2    118014771.2        288       3449        116.9 MB   

  reader_memory_h df_memory_h file_size_h  repeats  reads_the_same  
0        110.6 MB   288 Bytes   139 Bytes        5           False  
1        110.8 MB   288 Bytes      1.1 kB        5            True  
2        118.0 MB   288 Bytes      3.4 kB        5            True  

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

pandas_save_profiler-0.0.0.tar.gz (6.1 kB 查看哈希

已上传 source

内置分布

pandas_save_profiler-0.0.0-py3-none-any.whl (7.5 kB 查看哈希

已上传 py3