From dcff8433edbe187e6cfe1cce72267fe530322c6c Mon Sep 17 00:00:00 2001 From: mattbk Date: Wed, 5 Apr 2023 19:05:57 -0500 Subject: [PATCH] Orient JSON by records. --- app.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 56e7d7b..cf0c436 100644 --- a/app.py +++ b/app.py @@ -11,13 +11,13 @@ api = Api(app) class Users(Resource): def get(self): data = pd.read_csv('users.csv') # read CSV - data = data.to_dict() # convert dataframe to dictionary + data = data.to_dict(orient = 'records') # convert dataframe to dictionary return {'data': data}, 200 # return data and 200 OK code class Locations(Resource): def get(self): data = pd.read_csv('locations.csv') # read CSV - data = data.to_dict() # convert dataframe to dictionary + data = data.to_dict(orient = 'records') # convert dataframe to dictionary return {'data': data}, 200 # return data and 200 OK code # Read some log files @@ -29,14 +29,13 @@ for file in file_list: list_stacked = pd.concat([list_stacked, file1]) # TODO Can we do this without numpy? list_stacked.replace(np.nan, 0, inplace=True) - -# TODO do I need to rearrange the data to a different format? I want all the -# data for one packet (one row) together. +#print(list_stacked.head()) class Packets(Resource): def get(self): data = list_stacked - data = data.to_dict() # convert dataframe to dictionary + data = data.to_dict(orient = 'records') # convert dataframe to dictionary + #data = data.to_json(orient='records') return {'data': data}, 200 # return data and 200 OK code api.add_resource(Users, '/users') # '/users' is our entry point for Users