0
import pandas as pd
import numpy as np    

data = {'a' : 0., 'b' : 1., 'c' : 2.}

s = pd.Series(data,index=['b','c','d','a'])
print (s)

OUTPUT IS : 

b    1.0
c    2.0
d    NaN
a    0.0
dtype: float64

I want to assign some values to NaN. Finally i got the answer. I was thinking to remove the nan with empty string "" and below is the code.

        data = pd.read_excel(i)
        data1 = data.replace(np.nan, '', regex=True)
        data1.columns = data1.columns.str.replace('Unnamed.*', '')
  • 1
    Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on how to ask a good question may also be useful. – yatu Apr 11 '20 at 12:21

1 Answers1

0

You can use fillna method of pandas.

s.fillna(0)

You can also replace with mean or median of Series

s.fillna(s.median()) 

#or

s.fillna(s.mean()) 
FAHAD SIDDIQUI
  • 631
  • 4
  • 22