Answer the question
In order to leave comments, you need to log in
How to solve TypeError: expected str, bytes or os.PathLike object, not list error?
You need to create a dataframe from csv files that are in folders from the archive
import os
# open a zip file
import zipfile
with zipfile.ZipFile('C:\DS\data\data.zip') as zip_ref:
zip_ref.extractall('C:\DS \data')
# define directories
path = os.listdir(f'C:\DS\data\data')
# create empty df
df = pd.DataFrame()
# read data from all files and append to df
for current_path, dirs , files in os.walk(path):
for file in files:
data_path = f'{current_path}/{file}'
temp_df=pd.read_csv(data_path)
df = pd.concat((df, temp_df))
print(df .shape)
Error: TypeError: expected str, bytes or os.PathLike object, not list
path yields
['2020-12-03',
'2020-12-04',
'2020-12-05',
'2020-12- 06',
'2020-12-07',
'2020-12-08',
'2020-12-09']
This is a list of folders from an archive that I unpacked
. How can I make this list readable?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question