Reputation: 1893
I have a dataframe with accident data of some streets:
I'd like to remove (or at least select) that first row that is indexed as np.nan
. I tried streets.loc[np.nan,:]
but that returns a KeyError: nan
. I'm not sure how else to specifically select that record.
Other than using pd.DataFrame.iloc[0,:]
(which is imprecise as it relies on location rather than index name) how can I select that specific record?
Upvotes: 1
Views: 102
Reputation: 636
You can do df = df.dropna()
This will remove all rows with at least one nan
value.
Optionally, you could also do df.dropna(inplace=True)
The parameter inplace
just means that you don't have to specify df = df.dropna()
and it will modify the original var for you.
You can find more info on this here: pandas.DataFrame.dropna
Upvotes: 1
Reputation: 48
I think there are two options you can do.
You can fill any random value to nan and then select it.
df.fillna(value={'ON STREET NAME': 'random'}) streets.loc['random',:]
assign another index column, but this can affect your dataframe later.
Upvotes: 1