hey guys i am new to python and have been trying to use google collaboratory notebook to learn pandas. i have been trying to import data but i was unable to do so, the error being :
`FileNotFoundError: [Errno 2] No such file or directory: './train.csv'`
but i had the csv file in my folder which my notebook is in.
This is the code i used to run. i had no idea why it doesnt work. Thanks for any suggestions.
train = pd.read_csv("./train.csv")
test = pd.read_csv("./test.csv")
Assuming you uploaded your files in Google colab correctly, I suspect that you're not using the exact location of the files (test.csv and
train.csv)
Once you navigate to the location of the files, find the location using
pwd
Once you find the location, you can read the files in pandas
train = pd.read_csv(Location_to_file)
test = pd.read_csv(location_to_file)
Related
I currently have a main python script which is working by analyzing a given csv file present in its own local working folder. With the aim of automatizing the process of analyzing more than one csv file, I'm currently trying to build another script which is performing the following tasks:
Download in local working folder a csv file, identified by its own name among the many in an online repository (a OneDrive folder), for which I have the corresponding URL (for the OneDrive folder, not directly the file).
Run the main script and analyze it.
Remove the analyzed csv file from local folder and repeat the process.
I'm having some issues with the identification and download of the csv files.
I've seen some approaches using 'request' module but they were more related to downloading directly a file corresponding to a given URL, not looking for it and taking it from an online repository. For this reason I'm not even sure about how to start here.
What I'm looking for is something like:
url = 'https://1drv.ms/xxxxxxxxx'
file_name = 'title.csv'
# -> Download(link = url, file = file_name)
Thanks in advance to anyone who'll take some time to read this! :)
I'm trying to set up a github so that all the code is self contained and the other authors don't need to post their entire path to certain files.
my code:
dataSet = pd.read_json("file://repository/Datasets/JSON/data.json", convert_dates=False)
This gives me this error:
URLError: <urlopen error [WinError 3] The system cannot find the path specified: '\\repository\\Datasets\\JSON\\data.json'>
As this is the way that the docs seem to describe how to do this, I'm stumped on how to do it
I'd say move the file into the same directory and simply use
dataSet = pd.read_json('data.json')
Once that works then you know for sure that it's not an issue with reading the file. The error suggests it's an issue with Windows reading the path to the file.
Not sure what editor you're using but in VS Code if you right click the file it allows you to copy the 'relative path' in relation to the file you're currently working on.
Sorry I can't be of more help.
Hi I am working on a project in data analysis with python where I have an XML file of around 2,8GB which is too large to open . I downloaded EmEditor which helped me open the file . The problem is when i try to load the file in python google colaboratory like this :
import xml.etree.ElementTree as ET
tree = ET.parse('dataset.xml') //dataset.xml is the name of my file
root = tree.getroot()
I get the result that No such file or directory: 'dataset.xml' exists . I have my dataset.xml file on my desktop and it can be opened using the EmEditor which gives me the idea that it can be edited and loaded via the EmEditor but I don't know . I would appreciate your help with helping me load the data in python
google colab.
Google Colab runs remotely on a computer from Google, and can't access files that are on your desktop.
To open the file in Python, you'll first need to transfer the file to your colab instance. There's multiple ways to do this, and you can find them here: https://colab.research.google.com/notebooks/io.ipynb
The easiest is probably this:
from google.colab import files
uploaded = files.upload()
for fn in uploaded.keys():
print('User uploaded file "{name}" with length {length} bytes'.format(
name=fn, length=len(uploaded[fn])))
Although keep in mind that every time you start a new colab session you'll need to reupload the file. This is because Google would like to use to the computer for someone else when you are not using it, and thus wipes all the data on the computer.
I want to import >1100 seismic time series files from Azure into a Azure online hosted Notebook for processing. My code currently copies the file directly into my project source directory instead of neatly into my "../data/" directory.
I can import things from all over the project using the "~/library/../" string. However, the same trick isn't working when I try to direct the data where to go.
I did some research online but most results don't seem to cover this particular use case. I've tried many variations of file paths but to no avail.
How can I write files to a directory relative to my home path?
import_path = "~/library/04_processedData/seismicflatfile.csv"
return_path = "RSN1100_KOBE_ABN-UP.csv"
blob_service.get_blob_to_path(container_name, "RSN1100_KOBE_ABN-UP.DT2", return_path)
You can get the local path with,
local_path = os.path.join(folder_path, file_name)
if not os.path.isfile(local_path):
blob_service.get_blob_to_path(CONTAINER_NAME, blob_name, local_path)
Refer the sample here
i got a permission denied error while i tried to open an excel file.
I dont have the ms excel complete version. I mean, im just using the trial version.
Could it be because of that?
my code has just 4 lines
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
dataset = pd.read_excel("E:\\ML")
It's something about how file open function works. I successfully reproduced your problem and find the way.
It's believed that you have a directory named ML in E disk, and maybe there are some excels files (such as *.xls or *.xlsx) in ML(I bet you just started learning machine learning). Now you try to load the excel data into your program, but you give the path E:\\ML, which is a directory instead of a file, so operation is forbidden by system when pandas try to serialize the directory as a file, which is the cause of error "Permission denied".
The method is that you're supposed to use file path like E:\\ML\\your_database_file_name.xls.
I hope it will work for you.
For me, it turns out that it was because I had the same Excel file opened (I kept getting the error while trying to push my work to Github) which was resolved immediately after I closed the MS Excel (the program using the file I wanted to push..)
I hope you find this helpful!