Orient JSON by records.
This commit is contained in:
parent
b16fb4a630
commit
dcff8433ed
11
app.py
11
app.py
|
@ -11,13 +11,13 @@ api = Api(app)
|
||||||
class Users(Resource):
|
class Users(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
data = pd.read_csv('users.csv') # read CSV
|
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
|
return {'data': data}, 200 # return data and 200 OK code
|
||||||
|
|
||||||
class Locations(Resource):
|
class Locations(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
data = pd.read_csv('locations.csv') # read CSV
|
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
|
return {'data': data}, 200 # return data and 200 OK code
|
||||||
|
|
||||||
# Read some log files
|
# Read some log files
|
||||||
|
@ -29,14 +29,13 @@ for file in file_list:
|
||||||
list_stacked = pd.concat([list_stacked, file1])
|
list_stacked = pd.concat([list_stacked, file1])
|
||||||
# TODO Can we do this without numpy?
|
# TODO Can we do this without numpy?
|
||||||
list_stacked.replace(np.nan, 0, inplace=True)
|
list_stacked.replace(np.nan, 0, inplace=True)
|
||||||
|
#print(list_stacked.head())
|
||||||
# TODO do I need to rearrange the data to a different format? I want all the
|
|
||||||
# data for one packet (one row) together.
|
|
||||||
|
|
||||||
class Packets(Resource):
|
class Packets(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
data = list_stacked
|
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
|
return {'data': data}, 200 # return data and 200 OK code
|
||||||
|
|
||||||
api.add_resource(Users, '/users') # '/users' is our entry point for Users
|
api.add_resource(Users, '/users') # '/users' is our entry point for Users
|
||||||
|
|
Loading…
Reference in New Issue
Block a user