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