I have Pandas DataFrame:
df = pd.read_csv("file.csv")
I need to count not all occurancies of columnn 'gender'
, but for the first 5 entries (would love to see code for any interval of rows, let's say from 10th to the 20th etc.)
Currently I am familliar only with this:
df[df['gender'] == 1].shape[0]
and more complicated with lambda:
A2_object = df.apply(lambda x: True if x['gender'] == 1 else False, axis=1)
A2 = len(A2_object[A2_object == True].index)
I am learning, and I see that loops don't work in dataframe the same way as in the lists or dictionaries.
I am trying something like that:
df[df['gender'] == 1 and df.index < 5].shape[0]
I love this post, but can't get my head around the examples.