I have just started my work on pandas. Currently I'm working on a dataset of NETFLIX.
In this dataset I want to add a new column which contains the total number of cast members in that particular movie or tv show. I can calculate the cast individually but I want to calculate all of them. Can someone help me to write this code ?
Here is what I'm trying to do:
def set_cast(val):
for i in df['cast']:
if val== "None":
return 0
else:
return len(df.loc[i,'cast'].split(', '))
df['num_of_cast'] = df['cast'].apply(set_cast)
That's how I'm trying to add number of cast in a new column but it's not working...The dataset contains 8807 rows so adding each of it individually is not possible for me.
Need a solution for this. Thanks