Python Forum

Full Version: How to insert data in a dataframe?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to insert lots of csvs in one dataframe. They are from zenodo and are charts from spotify. The .zip archive has three folders, 2017, 2018, 2019 that contain the csvs. I've tried this code, but I get an error saying no objects to concat:

header = 0
dfs = []
for file in glob.glob('Charts/*/201?/*.csv'):
    region = file.split('/')[1]
    dates = re.findall('\d{4}-\d{2}-\d{2}', file.split('/')[-1])
    weekly_chart = pd.read_csv(file, header=header, sep='\t')
    weekly_chart['week_start'] = datetime.strptime(dates[0], '%Y-%m-%d')
    weekly_chart['week_end'] = datetime.strptime(dates[1], '%Y-%m-%d')
    weekly_chart['region'] = region
    dfs.append(weekly_chart)

all_charts = pd.concat(dfs)
What should I try? The archive is here, it's the charts.zip: https://zenodo.org/record/4778563/files/...download=1
Not really using concat properly. I suggest instead of making an array of dataframes, that you just append the dataframes. You could likely do that just by changing line 2 to make dfs a dataframe rather than an array. THe rest of the code should work (eliminate line 12).