0

So I am given thousands of lines of data of which I inserted into a data frame using pandas. I would like to create plots that includes only 48 rows of data and after every 48 rows creating a new plot that has the next 48 rows and so on. I'm confused as to how to do that. I would also like to know how to graph only certain rows in my data frame in my line plot. P.S. this is my first question so I apologize for any formatting errors.

I isolated a certain column of my code "HP" and assigned into the variable hp by doing hp = df.HP. I also made a basic plot for the whole data already by doing hp.plot(x = '#', y = None, kind = 'line'). I've looked up my issue and tried using

hpnew = hp[seq(1, nrow(hp), 48), ]

hpnew.plot(x = '#', y = None, kind = 'line')

Where hp new would be every 48th row. It didn't work and I was left with the error message

NameError: name 'seq' is not defined

Initially I told to use

for i to range(hp):
  hp(i)

But I was left with a syntax error and was confused what to from there.

MVG
  • 1
  • 1

1 Answers1

0

You can use the answer by Roman Pekar here to bin your dataframe into groups of 48:

df.groupby(df.index / 48)

Then if you have some plotting function you can apply it to the grouped data:

def plot_function(df):
    df.plot( ... )
df.groupby(df.index / 48)['hp'].apply(plot_function)
ASGM
  • 11,051
  • 1
  • 32
  • 53