99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2021-04-15 閱讀量: 765
pandas賦值 為什么float類型轉(zhuǎn)變成了int?

從excel表格種讀取數(shù)據(jù),然后把一列的數(shù)據(jù)經(jīng)過簡單的加減乘除的數(shù)學(xué)運算后放到相應(yīng)的另一列中(index相同,columns變化)。


完成這樣一個功能,使用的是逐個賦值的方式,


data.iloc[i,Colu] = data.temp[i] #即把temp列的數(shù)據(jù)放到Colu列中

(其中Colu為變量)

調(diào)試中,發(fā)現(xiàn)data.temp[i]的數(shù)據(jù)明明是float類型,但是經(jīng)過賦值后到data.iloc[i,Colu]就變成了int型。


原因:讀取excel表格數(shù)據(jù)時,沒有指定數(shù)據(jù)類型。


import pandas as pd

data= pd.read_excel(file_directory,index_col=0)

因此數(shù)據(jù)被默認(rèn)為int型了。


解決方法:讀取數(shù)據(jù)時,指定需要計算或賦值的列為float型。

# 指定數(shù)據(jù)類型
data= pd.read_excel(file_directory,index_col=0,dtype={'A_QTY': float,'B_QTY': float,'temp': float,})


133.3333
0
關(guān)注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子