第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

檢查對象數(shù)據(jù)類型列值是浮點數(shù)還是字符串的函數(shù)

檢查對象數(shù)據(jù)類型列值是浮點數(shù)還是字符串的函數(shù)

MMTTMM 2021-08-24 17:31:07
我正在嘗試在 excel 中編寫一個等于 isnumber[column] 函數(shù)的函數(shù)數(shù)據(jù)集:feature1 feature2 feature3  123       1.07     1  231       2.08     3  122        ab      4  111       3.04     6  555        cde     8feature1: integer dtypefeature2: object dtypefeature3: integer dtype我試過這段代碼for item in df.feature2.iteritems():    if isinstance(item, float):       print('yes')    else:       print('no')我得到的結果是 no no no no no但我想要結果yesyesnoyesno當我嘗試檢查單個 feature2 值的類型時,這就是所見type(df.feature2[0]) = strtype(df.feature2[1]) = strtype(df.feature2[2]) = strtype(df.feature2[3]) = strtype(df.feature2[4]) = strBut clearly 0,1,3 should be shown as float, but they show up as str我做錯了什么?
查看完整描述

3 回答

?
繁星淼淼

TA貢獻1775條經(jīng)驗 獲得超11個贊

Iteritems 返回一個元組,((123, '1.07'), 1.07)由于您想遍歷每個值,請嘗試以下代碼。您只需要移除.iteritems()它,它就會像魅力一樣發(fā)揮作用。


df['feature2']=[1.07,2.08,'ab',3.04,'cde']

for item in df.feature2:

    if isinstance(item,float):

       print('yes')

    else:

       print('no')

這是您的輸出:


yes

yes

no

yes

no


查看完整回答
反對 回復 2021-08-24
?
慕尼黑8549860

TA貢獻1818條經(jīng)驗 獲得超11個贊

試試這個:


for i in range(len(df["feature2"])):

    test = df.loc[i,"feature2"]

    if isinstance(test, float):

        print('yes')

    else:

        print('no')


查看完整回答
反對 回復 2021-08-24
  • 3 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號