You are using a loop which is not required. The function return Pandas series just use to_csv() to export. Check the code below:
grp('Biology', 'Science').to_csv('output.csv')Python for loop on function with args for csv export
I have used the below function without giving the parameters and this function worked fine and could export the values to CSV, but when I tried using the function by passing parameters as shown below it is not export the values to CSV. There is no error and the function returns 0
def grp(department, group):
df = pd.DataFrame(data=students, columns=['Name', 'Department', 'Script'])
df = df[df.Department == department]
df['Script'] = 'ADD USER ' + df['Name'] + ' TO ' + group
return df['Script']
If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch