1

I want to select rows based on the index like 0 to 30 index & save them to a data frame and again pick the index from 30 to 60 & save them into the same data frame but different column and I want to do it multiple times. How can I do that?

I don't know how to do it, please help me out.

Amit Kumar
  • 11
  • 3

1 Answers1

0

If df is is your initial DataFrame:

df1 = pd.DataFrame(index = df.index)
df1['<=30'] = df[df.index <= 30]['your_col_of_interest']
df1['>30 & <60'] = df[(df.index > 30) & (df.index <= 60)]['your_col_of_interest']
chambeeee
  • 95
  • 9