Read Data into Google Colab Environment

227 Views Asked by At

I am trying to run a sentiment analysis code in google colab to increase the processing speed compared to running the code on my device. But I am running into a strange error, which I am not able to solve.

I mounted the drive using the following code:

from google.colab import drive
drive.mount('/content/drive')

Then I want to load a Pickle-File, which I have saved in MyDrive using the following code:

with open('/content/drive/MyDrive/data_colab_new.pkl', 'rb') as file:
    data = pickle.load(file)

But I get the following error message:

EOFError Traceback (most recent call last) in 2 with open('/content/drive/MyDrive/data_colab_new.pkl', 'rb') as file: 3 # Load the pickle file ----> 4 data = pickle.load(file)

EOFError: Ran out of input

I already googled and the only explantion I found was that the Pickle-File is empty. But I checked multiple times now and I am sure that the file is not empty.

What could be another reason for that error and do you know any way to fix it? I`m not able to figure it out myself.

1

There are 1 best solutions below

0
Garry Osborne On

use this in google colab to load the pickle file first.

from google.colab import files
files.upload()

then pickle load like this

f = open('model.pkl', 'rb')
model = pickle.load(f)