No such file or directory: 'final_data_1.npy' - python

I am trying this code using tensorflow and numpy. However, I am getting an error.
import numpy as np
from tensorflow.python.framework import ops
np.random.seed(1)
ops.reset_default_graph()
ops.reset_default_graph()
#final_data_1 and 2 are the numpy array files for the images in the folder img and annotations.csv file
#total of 5 GB due to conversion of values to int
Z2= np.load('final_data_1.npy')
Z1= np.load('final_data_2.npy')
print(Z2[:,0])
print(Z1.shape)
my error is:
FileNotFoundError: [Errno 2] No such file or directory: 'final_data_1.npy'
Can you suggest a solution?

Like the Error message implies you have to name the right directory where this file "final_data_1.npy" is located at:
Example
import pandas as pd
df = pd.read_csv("./Path/where/you/stored/table/data.csv")
print(df)
Same goes with the function .load()
You have to add the directory of this file
np.load('./User/Desktop/final_data_1.npy')
Without naming the directory where the file is located your computer doesn't know where "final_data_1" is

Related

How can I read csv form kaggle

I want to read a csv-File from kaggle:
import os
import pandas as pd
df = pd.read_csv('/kaggle/input/ibm-hr-analytics-attrition-dataset/WA_Fn-UseC_-HR-Employee-Attrition.csv')
print("Shape of dataframe is: {}".format(df.shape))
But I get this error:
FileNotFoundError: [Errno 2] No such file or directory: '/kaggle/input/ibm-hr-analytics-attrition-dataset/WA_Fn-UseC_-HR-Employee-Attrition.csv'
I took the file path from kaggle.
Thank you for any help.
You have to adapt that path to the downloaded file.
df = pd.read_csv('/kaggle/input/ibm-hr-analytics-attrition-dataset/WA_Fn-UseC_-HR-Employee-Attrition.csv')
Is only an example path. Everyone has to change this path to the location where the downloaded .csv file from their homepage got saved.
The .csv file for download is available here:
https://www.kaggle.com/datasets/pavansubhasht/ibm-hr-analytics-attrition-dataset

How to list files from Dataset object in Azure Pipeline

I am trying to list files from Dataset in Azure pipeline (build) but getting error, I tried below two ways
Method #1
from azureml.core import Workspace, Dataset
import os
ws = Workspace.from_config()
dataset = Dataset.get_by_name(ws, "<dataset-name>")
print(os.listdir(str(dataset.as_mount())))
FileNotFoundError: [Errno 2] No such file or directory:
'<azureml.data.dataset_consumption_config.DatasetConsumptionConfig
object at >'
Method #2
from azureml.core import Workspace, Dataset
import os
ws = Workspace.from_config()
dataset = Dataset.get_by_name(ws, "<dataset-name>")
data = dataset.mount()
data.start()
print(os.listdir(data.mount_point))
Error: Mount is only supported on Unix or Unix-like operating systems
with the native package libfuse installed.
Can anyone please help me with this, I am stuck at it from sometime.

IsADirectoryError: [Errno 21] importing data

I am trying to access to my data on my drive for train the model but i received this error can anyone please gives me a piece of advice
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import pandas as pd
import seaborn as sns
import pickle
import random
with open("/content/drive/MyDrive/traffic_light_images/Train", mode='rb') as training_data:
train=pickle.load(training_data)
IsADirectoryError Traceback (most recent call last)
<ipython-input-10-e2ad2e076f9c> in <module>()
----> 1 with open("/content/drive/MyDrive/traffic_light_images/Train", mode='rb') as training_data:
2 train=pickle.load(training_data)
IsADirectoryError: [Errno 21] Is a directory: '/content/drive/MyDrive/traffic_light_images/Train'
The error is raised since you are passing a path to a directory (/content/drive/MyDrive/traffic_light_images/Train) instead of a file. Make sure to pass the path to the file instead of the directory.
You should add the file name and its extension after your directory like "/content/drive/MyDrive/traffic_light_images/Train/train_data.csv". Then, it is called a path.

OSError: [Errno 36] File name too long: for python package and .txt file, pandas opening

Error OSError: [Errno 36] File name too long: for the following code:
from importlib_resources import open_text
import pandas as pd
with open_text('package.data', 'librebook.txt') as f:
input_file = f.read()
dataset = pd.read_csv(input_file)
Ubuntu 20.04 OS, this is for a python package, init.py file
I dont want to use .readlines()
Can I structure this code differently to not have this outcome occur? Do I need to modify my OS system? Some of the help I found looked to modify OS but dont want to do this if I dont need to. Thank you.
why not just pass in the name of the file and not the contents
dataset = pd.read_csv('librebook.txt')
from importlib_resources import path
import pandas as pd
with path('package.data', 'librebook.txt') as f:
dataset = pd.read_csv(f)

python - numpy FileNotFoundError: [Errno 2] No such file or directory

I have this code:
import os.path
import numpy as np
homedir=os.path.expanduser("~")
pathset=os.path.join(homedir,"\Documents\School Life Diary\settings.npy")
if not(os.path.exists(pathset)):
ds={"ORE_MAX_GIORNATA":5}
np.save(pathset, ds)
But the error that he gave me is:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Maicol\\Documents\\School Life Diary\\settings.npy'
How can I solve this? The folder isn't created...
Thanks
Looks like you're trying to write a file to a directory that doesn't exist.
Try using os.mkdir to create the directory to save into before calling np.save()
import os
import numpy as np
# filename for the file you want to save
output_filename = "settings.npy"
homedir = os.path.expanduser("~")
# construct the directory string
pathset = os.path.join(homedir, "\Documents\School Life Diary")
# check the directory does not exist
if not(os.path.exists(pathset)):
# create the directory you want to save to
os.mkdir(pathset)
ds = {"ORE_MAX_GIORNATA": 5}
# write the file in the new directory
np.save(os.path.join(pathset, output_filename), ds)
EDIT:
When creating your new directory, if you're creating a new directory structure more than one level deep, e.g. creating level1/level2/level3 where none of those folders exist, use os.mkdirs instead of os.mkdir.
os.mkdirs is recursive and will construct all of the directories in the string.

Categories

Resources