I need some help.
Let's say I have the below dataframe called venues_df
I also have this function: return_most_common_venues
def return_most_common_venues(row, 4):
# Selects the row values
row_values = row.iloc[1:]
# Sorts the selected row values
row_values_sorted = row_values.sort_values(ascending=False)
# Returns the column name of the first 4 sorted values
return row_values_sorted.index.values[0:4]
If I apply my function on the first row:
return_most_common_venues(venues_df.iloc[0, :], 4)
The result will be an array (the below tables are for illustration purposes):
array (['Bar', 'Restaurant', 'Park', 'Gym'])
The problem is when I apply my function to the second row.
return_most_common_venues(venues_df.iloc[1, :], 4)
I will get
array(['Park', 'Restaurant', 'Gym', 'SuperMarket'])
What I need is for it to return:
array (['Bar', 'Restaurant', 'Not Available', 'Not Available'])
If the value is zero I need it to return 'Not Available' instead of the column names "Gym' and 'SuperMarket'
How can I modify my function to return what i need?
Thank you for your help!
Efren