![](/img/trans.png)
[英]How to really share a Jupyter notebook uploaded to Google Colab?
[英]How to implement this Jupyter notebook on Google Colab?
我剛開始使用谷歌 Colab 幾個小時前,我正在嘗試弄清楚我們如何讀取、寫入和保存內容等。
我在 Jupyter 筆記本上有此代碼,但在保存文件的最后一部分時遇到問題,我想將其保存在本地計算機或 Google Drive 上?
import pandas as pd
pd.set_option('display.max_columns', 999)
#load data
df = pd.read_csv('D:\\Project\\database\\Isolation Forest\\IF 15 PERCENT.csv')
df.shape
#data info
info = df.info()
print(info)
#data description
describe = df.describe() #print(describe)
f = open('D:\\Project\\database\\Isolation Forest\\Final Description IF TEST11.txt', "w+")
print(describe, file=f)
f.close()
和
谷歌 Colab 代碼:
import pandas as pd
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
link = '......'
fluff, id = link.split('=')
print (id) # Verify that you have everything after '='
downloaded = drive.CreateFile({'id':id})
downloaded.GetContentFile('IF 15 PERCENT.csv')
df = pd.read_csv('IF 15 PERCENT.csv',index_col=None)
info = df.info()
print(info)
describe = df.describe()
我現在真的不知道如何將它保存為 txt 文件和 w+
謝謝你。
這將以文本格式保存您的數據框:
tfile = open('test.txt', 'w+')
tfile.write(describe.to_string())
tfile.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.