Unable to read csv file in jupyter notebook - pandas

I was trying to read csv file in jupyter notebook but it showed error of filenotfound. Then I tried to check whether my file is present then it shoewd false as output. But I have checked the file location in my files explorer and the csv file is present .How should I read the file?
import os
os.path.isfile(r'C:\Users\Ritesh\Downloads\Data\Amazon_Products.csv')
Screenshot of code and error

maybe try:
import pandas as pd
df = pd.read_csv('your-filepath')
you could also try to move the file into your project directory so that it is in the same folder as the .ipynb

Related

MWAA load custom file info to DAG

I'm trying to use a file in a DAG.
The codes I want to use is basically this:
conf_device_info = OmegaConf.load(f"./config/{dag_name}/config_dtype.json")
and my bucket is currently like this:
my-bucket
--/ dags
-- /config
--/{dag_name}
--/config_dtype.json
-- dag_with_the_code.py
-- /utils
--s3_manager.py
When I import s3_manager with "import utils.s3_manager" , it goes fine.
When I try to run the code the OmegaConf code, it says
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/airflow/config/{dag_name}/config_dtype.json'
What should I do to do what I'm trying to acheive?
Why is import working and referencing file with absolute path not working..?
Thanks in advance.

Google Colab - Not able to import API key file

I have a code in Google Colab which uses a Python package called Atlite, which in turn retrieves data from the Climate Data Store (CDS) through the use of an API key.
When running this code in Python I just need to have the file containing the key saved in a specific folder and then the code runs perfectly fine.
When I try to run the code in Google Colab the following error arises:
**Exception: Missing/incomplete configuration file: /root/.cdsapirc
**
I have the file ".cdsapirc" in my computer but when I try to import it to the "/root" folder in Google Colab it just does not get imported. I can import a .py file, but when I try to import the ".cdsapirc" file (which is basically a txt file) it does not work.
Could someone please help me to solve this issue?
Thank you!
Regards,
Sebastian
If uploading the .cdsapirc file doesn't work, you could try creating it inside Google Colab using a simple Python script:
uid = "<your uid>"
apikey = "<your api-key"
with open("/root/.cdsapirc", "w") as f:
print("url: https://cds.climate.copernicus.eu/api/v2", file=f)
print(f"key: {uid}:{apikey}", file=f)
You can get the uid and apikey either from CDS after logging in or you open you local .cdsapirc file and look them up there, see here for more information.
There might be a nicer solution by someone more familiar with Google Colab though.

Convert from path gives an OS error:too many open files for converting PDF files into images

I'm trying to convert PDF files into images using convert_from_path but it gives an OS_error:too many open files.It works fine for converting some PDF files.
from pdf2image import convert_from_path
import os
#Folder Path
path = '/home/Input'
#Change the directory
os.chdir(path)
# Read pdf File
from pathlib import Path
pdf_search = Path(path).glob("*.pdf")
print(pdf_search)
#pdf_files =[str(file.absolute()) for file in pdf_search]
#print(pdf_files)
# iterate through all file
for pdf in pdf_search:
images=convert_from_path(pdf,output_folder='/home/Output',fmt='jpg',output_file='OFD')
The error is:
OSError: [Errno 24] Too many open files:

TypeError: 'module' object is not callable in Google Colab

I am getting the error when I run this code in google Colab
folders = glob('/content/drive/MyDrive/Data/train/*')
[![enter image description here]
You tried to use glob method directly, take the following code sample which was tested in Google colab environment. It should help to fix your issue.
from google.colab import drive
drive.mount('/gdrive')
import glob
path = glob.glob("/gdrive/MyDrive/*")
for file_or_folder in path:
print(file_or_folder)
For this issue, the path should be defined differently.
For that, initially import glob and drive module as mentioned below
from google.colab import drive
drive.mount('/gdrive')
import glob
And then using this, you can easily access the file as follows
folders = glob.glob('/gdrive/MyDrive/Datasets/Tomato/train/*')
Here if you see the difference in the copied path and the defined path is
'/content/drive/MyDrive/Datasets/Tomato/test' is what coppid form the drive
'/gdrive/MyDrive/Datasets/Tomato/train/*' is how you need to define the path

trouble accessing files on mounted google drive in colab

I have my google drive mounted in colab using:
from google.colab import drive
drive.mount('/content/gdrive')
Under My Drive, I have a folder called Data whose content I wish to access. The problem is, whenever I try to do something with this folder, either by just checking whether it is there:
!ls /content/gdrive/My\ Drive/
or trying to read a csv in that folder:
datapath = '/content/gdrive/My Drive/Data/'
scores = pd.read_csv(datapath+'Scores.csv')
It creates an empty folder with the same name (Data) under My Drive, and returns an error saying no file was found in Data. When I use !ls, it shows a folder named Data and a file named 'Data (1)' under My Drive.
from google.colab import drive
drive.mount('/content/gdrive')
import pandas as pd
df = pd.read_csv('/content/gdrive/My Drive/Data/Scores.csv')
df.head()