I am testing pandas.groupby function and have generated a random dataframe
df = pd.DataFrame(np.random.randint(5,size=(6,3)), columns=list('abc'))
in a random case df is:
a b c
0 2 2 2
1 1 4 2
2 3 0 1
3 2 1 3
4 0 2 2
5 2 1 4
when I use the following code to print out the groupby object, I get some interesting results.
def func(x):
print(x)
df.groupby("a").apply(lambda x: func(x))
a b c
0 0 1 4
a b c
0 0 1 4
a b c
2 2 4 1
3 2 2 1
a b c
1 4 0 0
4 4 4 3
Could anybody let me know why index 0 appear twice in this case?