I'm trying to migrate a JupyterLab notebook to Google Colab. In JupyterLab, when I have the notebook file and the associated csv files in the same directory, it is easy to import the data using numpy's loadtxt function as follows:
import numpy as np
filein = "testfile.csv"
data = np.loadtxt(open(filein, "rb"), delimiter=",", skiprows=1)
For various reasons I'd like to continue to use np.loadtxt in Colab. However when I try the same code there, it can't find the csv file despite it residing in the same Google Drive location as the notebook file. I get this error: "FileNotFoundError: [Errno 2] No such file or directory: 'testfile.csv'"
.
I gather I somehow need to provide a path to the file, but haven't been able to figure out how to do this. Is there any straightforward way to use np.loadtxt?
from Importing CSV file into Google Colab using numpy loadtxt
No comments:
Post a Comment