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

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

    2. <small id='XXmo6'></small><noframes id='XXmo6'>

        <legend id='XXmo6'><style id='XXmo6'><dir id='XXmo6'><q id='XXmo6'></q></dir></style></legend>

      1. pandas 數(shù)據(jù)框?qū)⒘蓄愋娃D(zhuǎn)換為字符串或分類

        pandas dataframe convert column type to string or categorical( pandas 數(shù)據(jù)框?qū)⒘蓄愋娃D(zhuǎn)換為字符串或分類)
      2. <small id='g1Bvd'></small><noframes id='g1Bvd'>

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

              <tfoot id='g1Bvd'></tfoot>

                    <tbody id='g1Bvd'></tbody>

                • 本文介紹了 pandas 數(shù)據(jù)框?qū)⒘蓄愋娃D(zhuǎn)換為字符串或分類的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  如何將 pandas 數(shù)據(jù)框的單列轉(zhuǎn)換為字符串類型?在下面的住房數(shù)據(jù) df 中,我需要將郵政編碼轉(zhuǎn)換為字符串,以便在運(yùn)行線性回歸時(shí),郵政編碼被視為分類而不是數(shù)字.謝謝!

                  How do I convert a single column of a pandas dataframe to type string? In the df of housing data below I need to convert zipcode to string so that when I run linear regression, zipcode is treated as categorical and not numeric. Thanks!

                  df = pd.DataFrame({'zipcode': {17384: 98125, 2680: 98107, 722: 98005, 18754: 98109, 14554: 98155}, 'bathrooms': {17384: 1.5, 2680: 0.75, 722: 3.25, 18754: 1.0, 14554: 2.5}, 'sqft_lot': {17384: 1650, 2680: 3700, 722: 51836, 18754: 2640, 14554: 9603}, 'bedrooms': {17384: 2, 2680: 2, 722: 4, 18754: 2, 14554: 4}, 'sqft_living': {17384: 1430, 2680: 1440, 722: 4670, 18754: 1130, 14554: 3180}, 'floors': {17384: 3.0, 2680: 1.0, 722: 2.0, 18754: 1.0, 14554: 2.0}})
                  print (df)
                         bathrooms  bedrooms  floors  sqft_living  sqft_lot  zipcode
                  722         3.25         4     2.0         4670     51836    98005
                  2680        0.75         2     1.0         1440      3700    98107
                  14554       2.50         4     2.0         3180      9603    98155
                  17384       1.50         2     3.0         1430      1650    98125
                  18754       1.00         2     1.0         1130      2640    98109
                  

                  推薦答案

                  你需要astype:

                  df['zipcode'] = df.zipcode.astype(str)
                  #df.zipcode = df.zipcode.astype(str)
                  

                  <小時(shí)>

                  用于轉(zhuǎn)換為分類:

                  df['zipcode'] = df.zipcode.astype('category')
                  #df.zipcode = df.zipcode.astype('category')
                  

                  另一種解決方案是分類:

                  Another solution is Categorical:

                  df['zipcode'] = pd.Categorical(df.zipcode)
                  

                  數(shù)據(jù)樣本:

                  import pandas as pd
                  
                  df = pd.DataFrame({'zipcode': {17384: 98125, 2680: 98107, 722: 98005, 18754: 98109, 14554: 98155}, 'bathrooms': {17384: 1.5, 2680: 0.75, 722: 3.25, 18754: 1.0, 14554: 2.5}, 'sqft_lot': {17384: 1650, 2680: 3700, 722: 51836, 18754: 2640, 14554: 9603}, 'bedrooms': {17384: 2, 2680: 2, 722: 4, 18754: 2, 14554: 4}, 'sqft_living': {17384: 1430, 2680: 1440, 722: 4670, 18754: 1130, 14554: 3180}, 'floors': {17384: 3.0, 2680: 1.0, 722: 2.0, 18754: 1.0, 14554: 2.0}})
                  

                  print (df)
                         bathrooms  bedrooms  floors  sqft_living  sqft_lot  zipcode
                  722         3.25         4     2.0         4670     51836    98005
                  2680        0.75         2     1.0         1440      3700    98107
                  14554       2.50         4     2.0         3180      9603    98155
                  17384       1.50         2     3.0         1430      1650    98125
                  18754       1.00         2     1.0         1130      2640    98109
                  
                  print (df.dtypes)
                  bathrooms      float64
                  bedrooms         int64
                  floors         float64
                  sqft_living      int64
                  sqft_lot         int64
                  zipcode          int64
                  dtype: object
                  
                  df['zipcode'] = df.zipcode.astype('category')
                  
                  print (df)
                         bathrooms  bedrooms  floors  sqft_living  sqft_lot zipcode
                  722         3.25         4     2.0         4670     51836   98005
                  2680        0.75         2     1.0         1440      3700   98107
                  14554       2.50         4     2.0         3180      9603   98155
                  17384       1.50         2     3.0         1430      1650   98125
                  18754       1.00         2     1.0         1130      2640   98109
                  
                  print (df.dtypes)
                  bathrooms       float64
                  bedrooms          int64
                  floors          float64
                  sqft_living       int64
                  sqft_lot          int64
                  zipcode        category
                  dtype: object
                  

                  這篇關(guān)于 pandas 數(shù)據(jù)框?qū)⒘蓄愋娃D(zhuǎn)換為字符串或分類的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Folium Choropleth + GeoJSON raises AttributeError: #39;NoneType#39;(Folium Choropleth + GeoJSON 引發(fā) AttributeError: NoneType)
                  How to share pandas DataFrame object between processes?(如何在進(jìn)程之間共享 pandas DataFrame 對(duì)象?)
                  Why does calling Python#39;s #39;magic method#39; not do type conversion like it would for the corresponding operator?(為什么調(diào)用 Python 的“魔術(shù)方法不像對(duì)應(yīng)的運(yùn)算符那樣進(jìn)行類型轉(zhuǎn)換?) - IT屋-程序員軟件開(kāi)發(fā)技
                  Convert strings to float in all pandas columns, where this is possible(在所有 pandas 列中將字符串轉(zhuǎn)換為浮點(diǎn)數(shù),這是可能的)
                  pandas - how to convert all columns from object to float type(pandas - 如何將所有列從對(duì)象轉(zhuǎn)換為浮點(diǎn)類型)
                  Converting pandas.DataFrame to bytes(將 pandas.DataFrame 轉(zhuǎn)換為字節(jié))
                    <tbody id='VN35s'></tbody>

                  <tfoot id='VN35s'></tfoot>

                    • <legend id='VN35s'><style id='VN35s'><dir id='VN35s'><q id='VN35s'></q></dir></style></legend>
                        <bdo id='VN35s'></bdo><ul id='VN35s'></ul>

                        <small id='VN35s'></small><noframes id='VN35s'>

                          <i id='VN35s'><tr id='VN35s'><dt id='VN35s'><q id='VN35s'><span id='VN35s'><b id='VN35s'><form id='VN35s'><ins id='VN35s'></ins><ul id='VN35s'></ul><sub id='VN35s'></sub></form><legend id='VN35s'></legend><bdo id='VN35s'><pre id='VN35s'><center id='VN35s'></center></pre></bdo></b><th id='VN35s'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VN35s'><tfoot id='VN35s'></tfoot><dl id='VN35s'><fieldset id='VN35s'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 亚洲黄色一级 | 一级中国毛片 | 久久久久久毛片免费观看 | 久久精品欧美一区二区三区不卡 | 久久性av | av国产精品 | 精品国产乱码久久久久久蜜退臀 | 日本一区二区在线视频 | 日韩a在线 | 欧美日韩成人一区二区 | 亚洲一区二区久久 | 欧美在线观看一区 | 一区二区三区免费看 | 激情91| 先锋影音资源网站 | 黄色在线网站 | 欧美不卡视频 | 国产精品毛片一区二区在线看 | 亚洲国产精品一区 | 2022精品国偷自产免费观看 | 欧美a级成人淫片免费看 | 青青草精品视频 | 成人在线免费观看 | 午夜精 | 久久久久久久久久一区二区 | 中文字幕91av | 久久综合久久综合久久 | 精品一区二区三区四区五区 | 久久精品91久久久久久再现 | www国产成人免费观看视频,深夜成人网 | 国产精品久久99 | 伊人啪啪网 | 亚洲国产一区在线 | 小h片免费观看久久久久 | 日韩中出| 先锋资源站 | 狠狠操av | 精品免费视频 | 永久www成人看片 | 国产激情第一页 | 久久综合伊人 |