Code related question

Course Name: Unsupervised Learning in Trading, Section No: 8, Unit No: 9, Unit type: Notebook

Hello, 

I was confused why there is an empty space passed as argument under args? 

# Calculating WCSS for number of clusters ranging from 1 to 30
wcss_df["WCSS"] = wcss_df["Number of Clusters"].apply(
    fit_kmeans, args=(features_scaled, ))

Hey Amit, 



The 'args' parameter in the apply() function is a tuple.



So, if we are passing a single string argument, for example 'abc' , then args=(abc) will be interpreted by python as 3 separate arguments ('a', 'b', 'c'). This will result in an error.



To avoid this error, we pass the 'args' tuple with a trailing comma: args=(abc,)



This trailing comma allows python to understand that the content in the parentheses is a tuple of length 1. 



Hope this helps. 



Thank you, 

Palak Khanna