【问题标题】:How to save your data you've already loaded and processed in Google Colab notebook so you don't have to reload it everytime?如何保存您已经在 Google Colab 笔记本中加载和处理的数据,这样您就不必每次都重新加载?
【发布时间】:2019-01-27 03:19:12
【问题描述】:

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

【问题讨论】:

    标签: python pandas jupyter-notebook google-colaboratory


    【解决方案1】:

    This example notebook 提供了一些保存和加载数据的不同方式的示例。

    您实际上可以使用 pickle 保存任何 Python 对象,包括 Pandas 数据帧,但更常见的是使用 Pandas 的方法之一进行序列化 pandas.DataFrame.to_csv、to_feather 等。

    我可能会推荐使用 GCS 命令行工具的选项,您可以通过前缀 ! 从笔记本内部运行该工具

    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/
    

    【讨论】:

    • 谢谢,我会试试这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 2020-10-16
    • 1970-01-01
    • 2019-07-28
    • 2019-12-17
    • 2019-01-02
    • 1970-01-01
    相关资源
    最近更新 更多