Reputation: 645
I have a 16x10 panda dataframe with arrays and NaN values inside. My goal is to get the first index of each array with python. Currently I try to achieve this by using
df.applymap(lambda x: x[0])
but due to the NaN in my dataframe I get the following error:
TypeError: ("'float' object is not subscriptable", 'occurred at index -2.0')
Any idea how to index in my dataframe? My dataframe
Upvotes: 1
Views: 135
Reputation: 645
df.applymap(lambda x: x[0] if not np.isnan(x).any() else np.NAN)
will do the job.
Upvotes: 1