I have table pulled from sqlite3 using sqlalchemy. This table holds the date and time of each showing of the car:

```
Id  Car     Code    ShowTime
1   Honda    A      10/18/2017 14:45
1   Honda    A      10/18/2017 17:10
3   Honda    C      10/18/2017 19:35
4   Toyota   B      10/18/2017 12:20
4   Toyota   B      10/18/2017 14:45

```

What would be the desired output is to seperate the date and put each timestamps on a list object:

```
"data":{
        'id': '1',
        'schedule': {
            'car': 'Honda',
            'show_date': '10/18/2017',
            'time_available': [
                '14:45',
                '17:10',        
            ],
            'code': 'A'

        }
    },{
        'id': '3',
        'schedule': {
            'car': 'Honda',
            'show_date': '10/18/2017',
            'time_available': [
                '19:35'
            ],
            'code': 'C'
        }
    },{
        'id': '4',
        'schedule': {
            'car': 'Toyota',
            'show_date': '10/18/2017',
            'time_available': [
                '12:20',
                '14:45'
            ],
            'code': 'B'
        }
    }

```

Any help is greatly appreciated!
['https://Stackoverflow.com/questions/56801384', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2341389/']
You can use pandas to split the `ShowTime` column:

```
In [22]: import pandas as pd

In [68]: df = pd.read_csv('test.csv')

In [69]: df.rename(columns={'Id':'id','Car':'car', 'Code':'code'}, inplace=True)

In [70]: df[['show_date', 'time_available']] = df.ShowTime.str.split(' ', expand=True)

In [71]: df.drop('ShowTime', axis=1, inplace=True)

In [72]: df
Out[72]:
   id     car code   show_date time_available
0   1   Honda    A  10/18/2017          14:45
1   1   Honda    A  10/18/2017          17:10
2   3   Honda    C  10/18/2017          19:35
3   4  Toyota    B  10/18/2017          12:20
4   4  Toyota    B  10/18/2017          14:45

```

`groupby` columns with categorical values and convert 'time\_available' column to list on the grouped dataframe:

```
In [134]: df_grp = df.groupby(['id', 'car','code', 'show_date'])

In [136]: df_grp_time_stacked = df_grp['time_available'].apply(list).reset_index()

In [138]: df_grp_time_stacked
Out[138]:
   id     car code   show_date  time_available
0   1   Honda    A  10/18/2017  [14:45, 17:10]
1   3   Honda    C  10/18/2017         [19:35]
2   4  Toyota    B  10/18/2017  [12:20, 14:45]

In [139]: df_grp_time_stacked['time_available'] = df_grp_time_stacked['time_available'].apply(lambda x:x[0] if (len(x)=
     ...: =1) else x)

In [140]: df_grp_time_stacked
Out[140]:
   id     car code   show_date  time_available
0   1   Honda    A  10/18/2017  [14:45, 17:10]
1   3   Honda    C  10/18/2017           19:35
2   4  Toyota    B  10/18/2017  [12:20, 14:45]

```

Now convert the dataframe to dict:

```
In [165]: raw_dict = df_grp_time_stacked.to_dict(orient='records')

In [166]: data = {'data':raw_dict}

In [167]: data
Out[167]:
{'data': [{'id': 1,
   'car': 'Honda',
   'code': 'A',
   'show_date': '10/18/2017',
   'time_available': ['14:45', '17:10']},
  {'id': 3,
   'car': 'Honda',
   'code': 'C',
   'show_date': '10/18/2017',
   'time_available': '19:35'},
  {'id': 4,
   'car': 'Toyota',
   'code': 'B',
   'show_date': '10/18/2017',
   'time_available': ['12:20', '14:45']}]}

```
Here you go:

```
import pandas as pd
from collections import defaultdict

data = {'Id': [1,1,3,4,4], 'Car': ['Honda','Honda','Honda','Toyota','Toyota'], 'Code': ['A','A','C','B','B'],
        'ShowTime': ['10/18/2017 14:45', '10/18/2017 17:10', '10/18/2017 19:35', '10/18/2017 12:20', '10/18/2017 14:45']}

df = pd.DataFrame(data)

# split time data into 2 columns
df['Date'], df['Time'] = df['ShowTime'].str.split(' ', 1).str

# drop unneeded column
df = df.drop(['ShowTime'],axis=1)

def create_dictionary(i):
    # select data
    selected_data = df.loc[df['Id'] == i]

    # get data
    id = selected_data['Id'].unique()
    car = selected_data['Car'].unique()
    code = selected_data['Code'].unique()
    date = selected_data['Date'].unique()
    time = selected_data['Time'].unique()

    # create dictionary
    dictionary_data = {'id': id[0], 'schedule': {'car': car[0], 'show_date': date[0],
                                                                'time_available': list(time), 'code': code[0]}}
    return dictionary_data

# get id list
id_list = list(df['Id'].unique())

# create data dictionary
out_data = defaultdict(list)

for i in id_list:
    one = create_dictionary(i)
    out_data["data"].append(one)

```

Output:

```
{'data': 
    [
    {'id': 1, 'schedule': {'car': 'Honda', 'show_date': '10/18/2017', 'time_available': ['14:45', '17:10'], 'code': 'A'}},
    {'id': 3, 'schedule': {'car': 'Honda', 'show_date': '10/18/2017', 'time_available': ['19:35'], 'code': 'C'}}, 
    {'id': 4, 'schedule': {'car': 'Toyota', 'show_date': '10/18/2017', 'time_available': ['12:20', '14:45'], 'code': 'B'}}
    ]})

```