I am getting this error:
FileNotFoundError: [Errno 2] File path/.csv does not exist: path/.csv
However the file actually is still there and I do not understand what it is wrong in my code for accessing it. Could you please have a look and see if you spot any error? Thank you
import pandas as pd
from os import listdir
from os.path import join, isfile
import os
def create_dataframe(paths):
def get_files_in_path(path):
return [f.split('.')[0] for f in listdir(path) if isfile(join(path, f))]
dataframes = {
(path, file): pd.read_csv(path + file + '.csv')
for path in paths
for file in get_files_in_path(path)
}
df = pd.concat(dataframes, names=['path', 'file', '_'])
paths = [f"path/My folder {f}/" for f in ['file1', 'file2', 'file3']]
data = create_dataframe(paths)
The error is in this line:
---> 18 for file in get_files_in_path(path)
The code should append in one unique dataframe all the csv
files stored in file1
, file2
, file3
folders.
The files are csv. They are called test+first.csv
, another_test.csv
. The path is path/My folder file1
and path/My folder file 2
and path/My folder file 3
.
The expected output would be something like this (in terms of indices with path and file): path would be user_id and file would be date in the image below.