Python中识别DataFrame中的nan


# 识别python中DataFrame中的nan
for i in pfsj.index:
  if type(pfsj.loc[i]['WZML']) == float:
    print('float value is ${}'.format(pfsj.loc[i]['WZML']))
  elif type(pfsj.loc[i]['WZML']) == str:
    print('str value is ${}'.format(pfsj.loc[i]['WZML']))

结果:

# 根据结果可知在DataFrame中,nan的类型为float
# 使用math中的isnan函数识别数据是否是nan类型的
for i in pfsj.index:
  if type(pfsj.loc[i]['WZML']) == float:
    if isnan(pfsj.loc[i]['WZML']):
      print('float type is ${}'.format(type(pfsj.loc[i]['WZML'])))

结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM