Reputation: 11
I have to set the values of the first 3 rows of dataset in column "alcohol" as NaN
newdf=pd.DataFrame({'alcohol':[np.nan]},index=[0,1,2])
wine.update(newdf)
wine
After running the code, no error is coming and dataframe is also not updated
Upvotes: 1
Views: 3113
Reputation: 863791
Use iloc
with get_loc
for position for column alcohol
:
wine.iloc[:3, wine.columns.get_loc('alcohol')] = np.nan
Or use loc
with first values of index:
wine.loc[wine.index[:3], 'alcohol'] = np.nan
Upvotes: 0
Reputation: 1824
Assuming alcohol
as column.
df.loc[:2, "alcohol"] = np.nan
#alternative
df.alcohol.iloc[:3] = np.nan
Upvotes: 1