Google colaboratory 文件b';content/train.csv';谷歌Colab不存在
第一次使用谷歌Colab。我使用了Kaggle API,并将数据加载到Google Colab中,但我似乎无法通过pandas打开它。我右键单击文件并复制了路径。然后我运行了以下代码:Google colaboratory 文件b';content/train.csv';谷歌Colab不存在,google-colaboratory,Google Colaboratory,第一次使用谷歌Colab。我使用了Kaggle API,并将数据加载到Google Colab中,但我似乎无法通过pandas打开它。我右键单击文件并复制了路径。然后我运行了以下代码: import pandas as pd train = pd.read_csv("content/train.csv") test = pd.read_csv('content/test.csv') 我得到的错误代码是: FileNotFoundError: File b'content/train.csv'
import pandas as pd
train = pd.read_csv("content/train.csv")
test = pd.read_csv('content/test.csv')
我得到的错误代码是:
FileNotFoundError: File b'content/train.csv' does not exist
以下是导致此错误的所有代码:
!pip install kaggle
from google.colab import files
files.upload() #Uploaded my kaggle.json file
!pip install -q kaggle
!mkdir -p ~/.kaggle
!cp kaggle.json ~/.kaggle/
!kaggle competitions download -c microsoft-malware-prediction
#Unzip the files:
!7z x train.csv.zip
!7z x sample_submission.csv.zip
!7z x test.csv.zip
#remove the zipped data
!rm train.csv.zip
!rm sample_submission.csv.zip
!rm test.csv.zip
import pandas as pd
train = pd.read_csv("content/train.csv")
test = pd.read_csv('content/test.csv')
print('read')
任何帮助都会很好 这也发生在我身上,但我能够通过使用新语法读取.csv文件来解决:
- 在上面的代码块中输入(第一个或第二个)
!pip安装-U-q PyDrive
从pydrive.auth导入GoogleAuth
从pydrive.drive导入GoogleDrive
来自google.colab导入验证
从oauth2client.client导入谷歌凭证
#验证并创建PyDrive客户端
auth.authenticate\u user()
gauth=GoogleAuth()
gauth.credentials=GoogleCredentials.get\u application\u default()
drive=GoogleDrive(gouth)
然后这样做:
link='链接到驱动器中的文件'
fluff,id=link.split('=')
download=drive.CreateFile({'id':id})
downloaded.GetContentFile('name\u of_file.csv')
df=pd.read\u csv(“name\u of \u file.csv”)
我遇到了同样的问题,解决方法是:
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# PyDrive reference:
# https://gsuitedevs.github.io/PyDrive/docs/build/html/index.html
# 2. Create & upload a file text file.
uploaded = drive.CreateFile({'title': 'Sample upload.txt'})
uploaded.SetContentString('Sample upload file content')
uploaded.Upload()
print('Uploaded file with ID {}'.format(uploaded.get('id')))
# 3. Load a file by ID and print its contents.
downloaded = drive.CreateFile({'id': uploaded.get('id')})
print('Downloaded content "{}"'.format(downloaded.GetContentString()))
from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
root_dir = "/content/gdrive/My Drive/"
base_dir = root_dir + 'app/'
and then each file is refreed as base_dir +file_name
从提供文件的完整路径,无论您在何处 试试下面的解决方案,如果你是从谷歌硬盘获取数据,希望它能起作用
data = pd.read_csv("/content/drive/My Drive/data/"name_of_the_csv_file")
要在Google Drive中打开文件,请执行以下操作:
df=pd.read\u csv(“复制并粘贴该文件的整个路径”)
路径中是否缺少前导的/
?i、 例如,/content/..
而不是content/..
。您好。是的,我已经包括在内了。我现在怀疑这是我获取数据的源的权限问题。谢谢你的帮助。