I'm fairly new to python and pandas so forgive me if this is a somewhat basic question. I am reading in some data from a csv file, I want to do a tally from column 'gender' of 'M', 'F' and NaN. The code below outputs this:
import pandas as pd
import numpy as np
df = pd.read_csv("....csv")
count = pd.value_counts(df['gender'],dropna=False)
This outputs:
M 22
F 3
NaN 1
However, I don't want to just see these as a tally, I want the values to be assigned to variables. I.e. have
male = pd.value_counts(df['gender'],'M',dropna=False)
or something similar, giving male = 22 (and the same for female and Nan), however I can't find an obvious way to do this using pandas. Any advice? Many thanks in advance!