2808 explained code solutions for 75 technologies


python-pandasFill empty data frame values with fillna()


import pandas as pd

data = pd.DataFrame({
  'Vendor': ['US', 'US', 'US', 'KR', 'KR'],
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, None, 405, None]
})

data = data.fillna(100)ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.fillna(

fills NaN values with given value

100

in our case we replace NaN values with 100


Usage example

import pandas as pd

data = pd.DataFrame({
  'Vendor': ['US', 'US', 'US', 'KR', 'KR'],
  'Phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'Phone Price': [204, 304, None, 405, None]
})

data = data.fillna(100)

print(data)
output
  Vendor Phone  Phone Price
0     US   ip5        204.0
1     US   ip6        304.0
2     US   ip8        100.0
3     KR   sms        405.0
4     KR    xi        100.0