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

        <tfoot id='MWQxM'></tfoot>

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

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

      2. <legend id='MWQxM'><style id='MWQxM'><dir id='MWQxM'><q id='MWQxM'></q></dir></style></legend>

        使用 Pandas 將整個數據幀從小寫轉換為大寫

        Convert whole dataframe from lower case to upper case with Pandas(使用 Pandas 將整個數據幀從小寫轉換為大寫)

          <bdo id='36vOI'></bdo><ul id='36vOI'></ul>

                <tbody id='36vOI'></tbody>
              <tfoot id='36vOI'></tfoot>

                <small id='36vOI'></small><noframes id='36vOI'>

                • <i id='36vOI'><tr id='36vOI'><dt id='36vOI'><q id='36vOI'><span id='36vOI'><b id='36vOI'><form id='36vOI'><ins id='36vOI'></ins><ul id='36vOI'></ul><sub id='36vOI'></sub></form><legend id='36vOI'></legend><bdo id='36vOI'><pre id='36vOI'><center id='36vOI'></center></pre></bdo></b><th id='36vOI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='36vOI'><tfoot id='36vOI'></tfoot><dl id='36vOI'><fieldset id='36vOI'></fieldset></dl></div>
                  <legend id='36vOI'><style id='36vOI'><dir id='36vOI'><q id='36vOI'></q></dir></style></legend>
                • 本文介紹了使用 Pandas 將整個數據幀從小寫轉換為大寫的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個如下所示的數據框:

                  I have a dataframe like the one displayed below:

                  # Create an example dataframe about a fictional army
                  raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks'],
                              'company': ['1st', '1st', '2nd', '2nd'],
                              'deaths': ['kkk', 52, '25', 616],
                              'battles': [5, '42', 2, 2],
                              'size': ['l', 'll', 'l', 'm']}
                  df = pd.DataFrame(raw_data, columns = ['regiment', 'company', 'deaths', 'battles', 'size'])
                  

                  我的目標是將數據框中的每個字符串都轉換為大寫,使其看起來像這樣:

                  My goal is to transform every single string inside of the dataframe to upper case so that it looks like this:

                  注意:所有數據類型均為對象,不得更改;輸出必須包含所有對象.我想避免將每一列一一轉換...我想一般在整個數據幀上進行.

                  Notice: all data types are objects and must not be changed; the output must contain all objects. I want to avoid to convert every single column one by one... I would like to do it generally over the whole dataframe possibly.

                  到目前為止我嘗試的是這樣做但沒有成功

                  What I tried so far is to do this but without success

                  df.str.upper()
                  

                  推薦答案

                  astype() 會將每個系列轉換為 dtype 對象(字符串),然后調用 str() 方法在轉換后的系列上從字面上獲取字符串并調用函數 upper() 就可以了.請注意,在此之后,所有列的 dtype 都會更改為 object.

                  astype() will cast each series to the dtype object (string) and then call the str() method on the converted series to get the string literally and call the function upper() on it. Note that after this, the dtype of all columns changes to object.

                  In [17]: df
                  Out[17]: 
                       regiment company deaths battles size
                  0  Nighthawks     1st    kkk       5    l
                  1  Nighthawks     1st     52      42   ll
                  2  Nighthawks     2nd     25       2    l
                  3  Nighthawks     2nd    616       2    m
                  
                  In [18]: df.apply(lambda x: x.astype(str).str.upper())
                  Out[18]: 
                       regiment company deaths battles size
                  0  NIGHTHAWKS     1ST    KKK       5    L
                  1  NIGHTHAWKS     1ST     52      42   LL
                  2  NIGHTHAWKS     2ND     25       2    L
                  3  NIGHTHAWKS     2ND    616       2    M
                  

                  您可以稍后使用 to_numeric():

                  In [42]: df2 = df.apply(lambda x: x.astype(str).str.upper())
                  
                  In [43]: df2['battles'] = pd.to_numeric(df2['battles'])
                  
                  In [44]: df2
                  Out[44]: 
                       regiment company deaths  battles size
                  0  NIGHTHAWKS     1ST    KKK        5    L
                  1  NIGHTHAWKS     1ST     52       42   LL
                  2  NIGHTHAWKS     2ND     25        2    L
                  3  NIGHTHAWKS     2ND    616        2    M
                  
                  In [45]: df2.dtypes
                  Out[45]: 
                  regiment    object
                  company     object
                  deaths      object
                  battles      int64
                  size        object
                  dtype: object
                  

                  這篇關于使用 Pandas 將整個數據幀從小寫轉換為大寫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 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 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `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='MdCjh'><style id='MdCjh'><dir id='MdCjh'><q id='MdCjh'></q></dir></style></legend>

                      <tfoot id='MdCjh'></tfoot>

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

                          <tbody id='MdCjh'></tbody>
                        • <bdo id='MdCjh'></bdo><ul id='MdCjh'></ul>

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

                          • 主站蜘蛛池模板: 中文字幕一区二区三区不卡 | 夜夜操天天艹 | 亚洲69p| 亚洲欧美日韩在线 | 一本一道久久a久久精品综合 | 国产精品久久久久久久久久三级 | a免费观看| 一区二区三区欧美 | 精品一区二区久久久久久久网站 | 国产亚洲成av人在线观看导航 | 亚洲欧美日韩在线 | 午夜精品久久久久久久星辰影院 | 欧美一区二不卡视频 | 亚洲精品日韩综合观看成人91 | 精品成人一区二区 | 日韩成人一区 | 老牛嫩草一区二区三区av | 中国91av | 中国一级特黄毛片大片 | 国产精品免费观看 | 手机av在线 | 国产美女特级嫩嫩嫩bbb片 | 欧美日韩亚洲一区 | 欧日韩在线观看 | 成人国产精品免费观看视频 | 天堂在线1 | 亚洲一区二区三区免费在线观看 | 一区精品在线观看 | 91在线视频 | 亚洲一区二区三区在线免费观看 | 在线国产一区二区三区 | 国产自产21区 | 操久久 | 国产精品久久二区 | 国产在线高清 | 精品久久久久一区二区国产 | 国产中文字幕在线观看 | 亚洲精品一区二区网址 | 五月天激情综合网 | 欧美v免费 | 一区二区三区免费在线观看 |