I have the following data in a csv file
SourceID BSs hour Type
7208 87 11 MAIN
11060 67 11 MAIN
3737 88 11 MAIN
9683 69 11 MAIN
I have the following python code.I want to plot a graph with the following specifications.
For each SourceID and Type I want to plot a graph of BSs over time. I would prefer if each SourceID and Type is a subplot on single plot.I have tried a lot of options using groupby, but can't seem to get it work.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
COLLECTION = 'NEW'
DATA = r'C:\Analysis\Test\{}'.format(COLLECTION)
INPUT_FILE = DATA + r'\in.csv'
OUTPUT_FILE = DATA + r'\out.csv'
with open(INPUT_FILE) as fin:
df = pd.read_csv(INPUT_FILE,
usecols=["SourceID", 'hour','BSs','Type'],
header=0)
df.drop_duplicates(inplace=True)
df.reset_index(inplace=True)

IndexErrorwas my fault - my code was settingnrowsto be too small to accommodate all of the plots in cases wherengrpsis not evenly divisible byncols. This is because I was doing floor division,ngrps // ncols, rather than ceiling division,-(-ngrps // ncols). This is now fixed in my answer.xlim=keyword argument torows.plot(..)), or by preventing the axes from being autoscaled by passingscalex=False, scaley=Falsetorows.plot(). I've made the latter change to my answer.scalexandscaleyto false in rows.plot() still the warning persists.I am not too worried about it at the moment.Please see my comment below about the new error. thanks.