Home > database >  How can I use fillna for a specific value?
How can I use fillna for a specific value?

Time:11-28

I already know how to use enter image description here

Failed try:

enter image description here

I want it to be

bmw 320i 2 plymouth reliant 1 honda civic 3

CodePudding user response:

Since the condition is not mentioned, the best solution I can provide is to use mask.

It replaces values where the condition is True.

CodePudding user response:

I want it to be bmw 320i 2 plymouth reliant 1 honda civic 3

You can fill the NaN in the first column with values from a series like this:

df = pd.DataFrame([[np.nan, "bmw 320i"],
                   [np.nan, "plymouth reliant"],
                   [np.nan, "honda civic"]],
                  columns=("origin", "car name"))
df2 = pd.Series([2,1,3]).to_frame(name="values")
df['origin'].fillna(value=df2["values"], inplace=True)
  • Related