pandas :要保存以包含dtypes的文件类型 [英] Pandas: type of file to save to contain dtypes
问题描述
我正在处理一些包含许多 DateTime
变量的数据集
.数据清理后,我总是保存一个 .csv
文件.但是,下次将文件加载到熊猫时,我必须再次转换 dtypes
,这将花费很长时间.因此,我想知道是否可以使用Pandas保存一种文件以避免这种情况.
I'm working on some datasets
contains many DateTime
variables. I always save a .csv
file after the data cleaning. However, when I load the file to pandas next time, I have to convert dtypes
again and it will take a long time. Thus, I wonder if there is a type of file I can save with Pandas to avoid this.
推荐答案
您可以使用 pickle
序列化对象.值得庆幸的是, pandas
具有本机功能来序列化和导出您的DataFrame.只需使用
You can serialize your object using pickle
. Thankfully pandas
has a native function to serialize and export your DataFrames. Just export using
df.to_pickle('your_file.pkl')
从文档中: https://pandas.pydata.org/pandas-docs/stable/generation/pandas.DataFrame.to_pickle.html
然后,您可以使用再次加载您的DataFrame
Then, you can load again your DataFrame using
df = pandas.read_pickle('your_file.pkl')
这篇关于 pandas :要保存以包含dtypes的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!