简体   繁体   中英

How to save your data you've already loaded and processed in Google Colab notebook so you don't have to reload it everytime?

我已经从pickle库中阅读了有关“棘手”的信息,但是这是否仅保存您训练过的模型,而不是保存例如从庞大的csv文件加载到变量中的实际数据框?

This example notebook has some examples of different ways to save and load data.

You can actually use pickle to save any Python object, including Pandas dataframes, however it's more usual to serialize using one of Pandas' methods pandas.DataFrame.to_csv , to_feather etc.

I would probably recommend the option which uses the GCS command-line-tool which you can run from inside your notebook by prefixing with !

import pandas as pd
# Create a local file to upload.
df = pd.DataFrame([1,2,3])
df.to_csv("/tmp/to_upload.txt")

# Copy the file to our new bucket.
# Full reference: https://cloud.google.com/storage/docs/gsutil/commands/cp
!gsutil cp /tmp/to_upload.txt gs://my-bucket/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM