1

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

1
  • 3
    what is wine here? Commented Nov 20, 2018 at 6:11

2 Answers 2

1

Assuming alcohol as column.

df.loc[:2, "alcohol"] = np.nan

#alternative
df.alcohol.iloc[:3] = np.nan
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.