I'm a beginner in python, just learning how to write functions. I've got a list of weights and gender, and am trying to split it to create two new lists according to the gender criteria. Using for loops, I've been successful so far:
df = pd.read_csv('brainweight.csv')
w = list(df['Weight'])
s = list(df['Sex'])
female_weight = []
male_weight = []
for sex, weight in zip (s, w):
if sex == 'f':
female_weight.append(weight)
else:
male_weight.append(weight)
How should I modify this for loop into a function where the variables = m/f (gender)?