Python Forum
How to insert data in a dataframe?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to insert data in a dataframe?
#1
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
Reply
#2
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).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 4,301 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  datetime intervals - dataframe selection (via plotted data) karlito 0 1,714 Nov-12-2019, 08:16 AM
Last Post: karlito
  How to add data to the categorical index of dataframe as data arrives? AlekseyPython 1 2,363 Oct-16-2019, 06:26 AM
Last Post: AlekseyPython
  Insert Pandas Data Frame into Teradata DB kylenater 0 5,702 Jul-19-2019, 04:53 PM
Last Post: kylenater
  Inserting data from python list into a pandas dataframe mahmoud899 0 2,620 Mar-02-2019, 04:07 AM
Last Post: mahmoud899
  Insert images in a folder into dataframe tofi 0 5,414 Dec-14-2018, 08:05 PM
Last Post: tofi
  [SOLVED on SO] Downsizing non-representative data in DataFrame volcano63 1 2,197 Sep-28-2018, 12:56 PM
Last Post: volcano63
  Pandas nested json data to dataframe FrankC 1 10,165 Aug-14-2018, 01:37 AM
Last Post: scidam
  Trying to import JSON data into Python/Pandas DataFrame then edit then write CSV Rhubear 0 4,106 Jul-23-2018, 09:50 PM
Last Post: Rhubear

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020