Pandas infrastructure data statistics plot with date per user

Viewed 129

I am trying to display some infrastructure usage daily statistics with Pandas but I'm a beginner and can't figure it out after many hours of research.

Here's my data types per column:

Name object UserService object ItemSize int64 ItemsCount int64 ExtractionDate datetime64[ns]

Each day I have a new extraction for each users, so I probably need to use the group_by before plotting.

Data sample:

          Name UserService  ItemSize  ItemsCount ExtractionDate
1   xyzf_s        xyfz        40           1     2018-12-12
2    xyzf1        xyzf        53           5     2018-12-12
3    xyzf2        xyzf        71           4     2018-12-12
4    xyzf3        xyzf        91           3     2018-12-12
14   vo12         vo          41           5     2018-12-12

One of the graph I am trying to display is as follow:

x axis should be the extraction date y axis should be the items count (it's divided by 1000 so it's by thousands of items from 1 to 100) Each line on the graph should represent a user evolution (to look at data spikes), I guess I would have to display the top 10 or 50 because it would be difficult to have a graph of 1500 users.

I'm also interested by any other way you would exploit those data to look for data increase and anomaly in data consumption.

1 Answers

Assuming the user is shown in the name columns and there is only one line per user per day, to get the plot you are explicitly asking for, you can use the following code:

 # Limit to 10 users
 users_to_plot = df.Name.unique()[:10]
 for u in users_to_plot:
      mask = (df['Name'] == u)
      values = df[mask]
      plt.plot('ExtractionDate','ItemsCount',data=values.sort_values('ExtractionDate'))

It's important to look at the data and think about what information you are trying to extract and what that looks like. It's probably worth exploring with some individuals first and getting an idea of what is the thing you are trying to identify. Think about what makes that unique and if you can make it pop on a graph.

Related