【发布时间】:2020-06-06 11:26:18
【问题描述】:
几小时前我才开始使用 Google Colab,我正在尝试了解如何读取、写入和保存内容等。
我在 Jupyter 笔记本上有这段代码,我在保存文件的最后部分遇到了问题,我想将其保存在本地计算机或 Google 云端硬盘上吗?
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()
和
Google 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+
谢谢。
【问题讨论】:
-
你是从某个链接下载的吗?
-
@Pygirl 链接指向我的 csv 文件在我的谷歌驱动器中
-
你遇到了什么问题?
标签: python pandas dataframe machine-learning google-colaboratory