I’m starting, and I haven’t written anything for a long time :-) I use the request library to get JSON data from the Cloud web security API encapsules to get some statistics about the website. In the end, I want to write "type trafic, timestamp and number "to the report file. The API response looks something like this:
{
"res": 0,
"res_message": "OK",
"visits_timeseries" : [
{
"id":"api.stats.visits_timeseries.human",
"name":"Human visits",
"data":[
[1344247200000,50],
[1344247500000,40],
...
]
},
{
"id":"api.stats.visits_timeseries.bot",
"name":"Bot visits",
"data":[
[1344247200000,10],
[1344247500000,20],
...
]
}
I am recovering Visit_timeseries data as follows:
r = requests.post('https://my.incapsula.com/api/stats/v1', params=payload)
reply=r.json()
reply = reply['visits_timeseries']
reply = pandas.DataFrame(reply)
I recover data in this form (date in unix time, number of visits):
print(reply[['name', 'data']].head())
name data
0 Human visits [[1500163200000, 39], [1499904000000, 73], [14...
1 Bot visits [[1500163200000, 1891], [1499904000000, 1926],...
I do not understand how to extract the fields that I want from a dataframe, so that I can only write them in excel. I need to change the data field to two lines (date, value). And only the name as the top lines.
Which would be great:
Human Visit Bot Visit
Date Value Value
Date Value Value
Date Value Value
Thank you for your help!