Orient JSON by records.
This commit is contained in:
		
							
								
								
									
										11
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user