Eva Marpaung Eva Marpaung - 1 year ago 113
Python Question

Chart with Pandas

Here's my code so far:

import os
import re
import sys
import io
import pandas as pd

def load_file(filename):
df =pd.read_csv('filename', sep='\t', header=None)
df[0]=pd.to_datetime(df[0], unit='s')
#print df[0]
return df

def main():
df = load_file()
daily = df.set_index(df[0]).groupby(pd.TimeGrouper(freq='D')) (df[3]).count()
perday= daily.groupby(pd.TimeGrouper(freq='D')).mean()
my_plot = perday.plot(kind='bar')
my_plot = perday.sort(columns=df[0],ascending=False).plot(kind='bar',legend=None,title="Total Session per day")

if __name__ == '__main__':

I have Http.log here. I want to make a chart with Pandas to show how many session in an hour, but I don't know how to define the

[x,y] where x = timestamps and y= sessions

Can anyone help me here?

Answer Source

if you want to parse/convert UNIX timestamp into Python/numpy/pandas datetime you can do it this way:

In [58]: pd.to_datetime('1437775199.837855', unit='s')
Out[58]: Timestamp('2015-07-24 21:59:59.837855')

or for the whole DF:

df['time'] = pd.to_datetime(df['time'], unit='s')

represent/print your timestamp in desired format:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download