I have a column with single elements as well as array-like elements but I don't think it looks like an array:
I need to extract first value from this array-like element. First, I check if it's array. If so I extract first elemnt, if not I return default value. I use this function:
def get_top_element(x):
if isinstance(x, np.ndarray):
return x[0]
return x
df_no_outliers['brand'] = df_no_outliers['brand'].apply(get_top_element)
Following error araises:
IndexError: index 0 is out of bounds for axis 0 with size 0
How can I make it work?
EDIT:
If I convert column to tuple then I get this:
tpl=tuple(df_no_outliers['brand'])
tpl