簡體   English   中英

將熊貓數據幀除以熊貓系列時僅獲取整數

[英]Getting only integers when dividing a pandas dataframe by a pandas series

我正在嘗試將數據幀除以熊貓系列,結果只在任何地方給出。

這是示例:

這是我的數據框 df

這是我的數據框 df

這是我的熊貓系列

這是我的熊貓系列

這就是我得到的結果

這就是我得到的結果

我正在使用熊貓部門。

df.divide(s, axis=1).

我嘗試使用 as.type(float),它沒有改變任何東西。

即使我單獨查看每一列,它也會給我相同的結果。

df.iloc[:,0].astype(float)/float(s.iloc[0])

它只給出一個列。

你有什么建議嗎?

df =     GROUP 2018-01 2018-02 2018-03 2018-04 2018-05
      PERIOD     
        1       2924   2547     3328    4519    3585
        2       1926   1856     2356    3315    nan
        3       1911   1625     2140    nan     nan
        4       1740   1462     nan     nan     nan
        5       1579   nan      nan     nan     nan

df is the result of an unstack(0)

s = GROUP
    2018-01   2924
    2018-02   2547
    2018-03   3328
    2018-04   4519
    2018-05   3585

when I do df.divide(s, axis = 1) I am getting only the ceiling value of the division.    
I am only getting 1 everywhere and nan there where there is nan in df. 
Everything is dtype float64.

我遇到了同樣的問題,並意識到我的浮點格式設置為在小數點右側顯示 0 位數字。 您可以像這樣調整浮動格式:

pd.options.display.float_format = '{:,.2f}'.format

其中 2 是要顯示的小數位數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM