I think this will solve your problem:
import pandas as pd data = pd.DataFrame({'cols1':[4, 5, 5, 4, 321, 32, 5], 'clol2':[45, 66, 6, 6, 1, 432, 3], 'class':['A', 'B', 'C', 'C', 'A', 'B', 'B']}) freq = pd.DataFrame({'class':['A', 'B', 'C'], 'nostoextract':[2, 2, 2], }) def bootstrap(data, freq): freq = freq.set_index('class')
Print
class clol2 cols1 0 A 45 4 4 A 1 321 1 B 66 5 5 B 432 32 3 C 6 4 2 C 6 5
If you do not want the result to be sorted by class, you can rearrange it at the end.
source share