I’m trying to figure out how to loop through a df and return not just one row of data, but a prescribed group of data. Hard to explain so I’ll use a simple example
import pandas as pd
data = [['apple', 1], ['orange', 2], ['pear', 3], ['peach', 4],['plum', 5], ['grape', 6]]
#index_groups = [0],[1,2],[3,4,5]
df = pd.DataFrame(data, columns=['Name', 'Number'])
for i in range(len(df)):
print(df['Number'][i])
Name Age
0 apple 1
1 orange 2
2 pear 3
3 peach 4
4 plum 5
5 grape 6
I need to know how to set my [i]
to be either 0, (1&2), (3&4&5)
(see the index_groups column)
I want to group my results but by a grouping I determine.
Do you mean something like
If you want just
Number
column