I have a folder trip_data
contains many csv file with date, which looks like this:
trip_data/
├── df_trip_20140803_1.csv
├── df_trip_20140803_2.csv
├── df_trip_20140803_3.csv
├── df_trip_20140803_4.csv
├── df_trip_20140803_5.csv
├── df_trip_20140803_6.csv
├── df_trip_20140804_1.csv
├── df_trip_20140804_2.csv
├── df_trip_20140804_3.csv
├── df_trip_20140804_4.csv
├── df_trip_20140804_5.csv
├── df_trip_20140804_6.csv
├── df_trip_20140805_1.csv
├── df_trip_20140805_2.csv
├── df_trip_20140805_3.csv
├── df_trip_20140805_4.csv
├── df_trip_20140805_5.csv
├── df_trip_20140805_6.csv
├── df_trip_20140806_1.csv
├── df_trip_20140806_2.csv
├── df_trip_20140806_3.csv
├── df_trip_20140806_4.csv
Now I want to load all these file separately by date with python pandas, means 4 DataFrame df_traip_20140803, df_traip_20140804, df_traip_20140805, df_traip_20140806
My code looks like this:
days = [20140803,20140804,20140805,20140806]
for day in days:
## Locate to the path
path ='./trip_data/df_trip_%d*.csv' % day
df = pd.read_csv(path, header=None, nrows=10,
names=['ID','lat','lon','status','timestamp'])
Which could not get the correct result. How can I do this?
I would collect all those CSV into dictionary of DataFrames with the following structure:
df['20140803']
- DF containing concatenated data belonging to alldf_trip_20140803_*.csv
CSV files.Solution:
Test:
Setup: