久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='oTCqd'></bdo><ul id='oTCqd'></ul>
  • <i id='oTCqd'><tr id='oTCqd'><dt id='oTCqd'><q id='oTCqd'><span id='oTCqd'><b id='oTCqd'><form id='oTCqd'><ins id='oTCqd'></ins><ul id='oTCqd'></ul><sub id='oTCqd'></sub></form><legend id='oTCqd'></legend><bdo id='oTCqd'><pre id='oTCqd'><center id='oTCqd'></center></pre></bdo></b><th id='oTCqd'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oTCqd'><tfoot id='oTCqd'></tfoot><dl id='oTCqd'><fieldset id='oTCqd'></fieldset></dl></div>
  • <legend id='oTCqd'><style id='oTCqd'><dir id='oTCqd'><q id='oTCqd'></q></dir></style></legend>

      <tfoot id='oTCqd'></tfoot>

    1. <small id='oTCqd'></small><noframes id='oTCqd'>

        pandas read_csv 列 dtype 設(shè)置為十進制但轉(zhuǎn)換為字符串

        pandas read_csv column dtype is set to decimal but converts to string(pandas read_csv 列 dtype 設(shè)置為十進制但轉(zhuǎn)換為字符串)
          <i id='nyvT3'><tr id='nyvT3'><dt id='nyvT3'><q id='nyvT3'><span id='nyvT3'><b id='nyvT3'><form id='nyvT3'><ins id='nyvT3'></ins><ul id='nyvT3'></ul><sub id='nyvT3'></sub></form><legend id='nyvT3'></legend><bdo id='nyvT3'><pre id='nyvT3'><center id='nyvT3'></center></pre></bdo></b><th id='nyvT3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nyvT3'><tfoot id='nyvT3'></tfoot><dl id='nyvT3'><fieldset id='nyvT3'></fieldset></dl></div>
          <legend id='nyvT3'><style id='nyvT3'><dir id='nyvT3'><q id='nyvT3'></q></dir></style></legend>
          1. <small id='nyvT3'></small><noframes id='nyvT3'>

            <tfoot id='nyvT3'></tfoot>

                <tbody id='nyvT3'></tbody>

                • <bdo id='nyvT3'></bdo><ul id='nyvT3'></ul>

                  本文介紹了pandas read_csv 列 dtype 設(shè)置為十進制但轉(zhuǎn)換為字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在使用 pandas (v0.18.1) 從名為test.csv"的文件中導(dǎo)入以下數(shù)據(jù):

                  I am using pandas (v0.18.1) to import the following data from a file called 'test.csv':

                  a,b,c,d
                  1,1,1,1.0
                  

                  我已將列 'c' 和 'd' 的 dtype 設(shè)置為 'decimal.Decimal' 但它們返回為類型 'str'.

                  I have set the dtype to 'decimal.Decimal' for columns 'c' and 'd' but instead they return as type 'str'.

                  import pandas as pd
                  import decimal as D
                  
                  df = pd.read_csv('test.csv', dtype={'a': int, 'b': float, 'c': D.Decimal, 'd': D.Decimal})
                  
                  for i, v in df.iterrows():
                      print(type(v.a), type(v.b), type(v.c), type(v.d))
                  

                  結(jié)果:

                  `<class 'int'> <class 'float'> <class 'str'> <class 'str'>`
                  

                  我還嘗試在導(dǎo)入后顯式轉(zhuǎn)換為十進制,但沒有成功(轉(zhuǎn)換為浮點有效但不是十進制).

                  I have also tried converting to decimal explicitly after import with no luck (converting to float works but not decimal).

                  df.c = df.c.astype(float)
                  df.d = df.d.astype(D.Decimal)
                  for i, v in df.iterrows():
                      print(type(v.a), type(v.b), type(v.c), type(v.d))
                  

                  結(jié)果:

                  `<class 'int'> <class 'float'> <class 'float'> <class 'str'>`
                  

                  以下代碼將str"轉(zhuǎn)換為decimal.Decimal",所以我不明白為什么 pandas 的行為方式不同.

                  The following code converts a 'str' to 'decimal.Decimal' so I don't understand why pandas doesn't behave the same way.

                  x = D.Decimal('1.0')
                  print(type(x))
                  

                  結(jié)果:

                  `<class 'decimal.Decimal'>`
                  

                  推薦答案

                  我覺得你需要轉(zhuǎn)換器:

                  import pandas as pd
                  import io
                  import decimal as D
                  
                  temp = u"""a,b,c,d
                             1,1,1,1.0"""
                  
                  # after testing replace io.StringIO(temp) to filename
                  df = pd.read_csv(io.StringIO(temp), 
                                   dtype={'a': int, 'b': float}, 
                                   converters={'c': D.Decimal, 'd': D.Decimal})
                  
                  print (df)
                         a    b  c    d
                      0  1  1.0  1  1.0
                  
                  for i, v in df.iterrows():
                      print(type(v.a), type(v.b), type(v.c), type(v.d))
                  
                      <class 'int'> <class 'float'> <class 'decimal.Decimal'> <class 'decimal.Decimal'>
                  

                  這篇關(guān)于pandas read_csv 列 dtype 設(shè)置為十進制但轉(zhuǎn)換為字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時,yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

                      1. <legend id='O9DFO'><style id='O9DFO'><dir id='O9DFO'><q id='O9DFO'></q></dir></style></legend>
                      2. <i id='O9DFO'><tr id='O9DFO'><dt id='O9DFO'><q id='O9DFO'><span id='O9DFO'><b id='O9DFO'><form id='O9DFO'><ins id='O9DFO'></ins><ul id='O9DFO'></ul><sub id='O9DFO'></sub></form><legend id='O9DFO'></legend><bdo id='O9DFO'><pre id='O9DFO'><center id='O9DFO'></center></pre></bdo></b><th id='O9DFO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='O9DFO'><tfoot id='O9DFO'></tfoot><dl id='O9DFO'><fieldset id='O9DFO'></fieldset></dl></div>

                        <tfoot id='O9DFO'></tfoot>

                      3. <small id='O9DFO'></small><noframes id='O9DFO'>

                          <bdo id='O9DFO'></bdo><ul id='O9DFO'></ul>

                            <tbody id='O9DFO'></tbody>
                            主站蜘蛛池模板: 在线观看亚洲欧美 | 黄色免费在线网址 | 国产精品美女一区二区三区 | 国产蜜臀97一区二区三区 | 久久久亚洲 | 国产精品日韩在线观看 | 欧美电影免费网站 | 精品日韩在线观看 | 免费黄视频网站 | 日韩在线观看网站 | 精品国产1区2区3区 一区二区手机在线 | 少妇诱惑av | 久久久久国产精品人 | 精品久久一区 | 国产成人福利在线 | 精久久久| 亚洲 精品 综合 精品 自拍 | 日韩一区二区av | 精品欧美一区二区精品久久久 | 亚洲国产一区二区三区 | 日本激情视频中文字幕 | 国产欧美精品区一区二区三区 | dy天堂| 久久99精品久久久久久国产越南 | www97影院| 中文字幕一区二区三区四区五区 | 亚洲精品一区二区三区在线 | 欧美乱操 | 亚洲精品2 | 91社影院在线观看 | 在线视频一区二区 | 日韩午夜电影在线观看 | 亚洲国产高清高潮精品美女 | 99视频免费 | 视频二区在线观看 | 国产在线观看一区二区 | 成年精品 | 男人天堂手机在线视频 | 日韩一区在线观看视频 | 久久精品视频99 | 成人黄色电影在线播放 |