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

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

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

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

    1. <tfoot id='OKvWb'></tfoot>

    2. 將 pandas.DataFrame 轉換為字節

      Converting pandas.DataFrame to bytes(將 pandas.DataFrame 轉換為字節)
    3. <i id='z9L4Q'><tr id='z9L4Q'><dt id='z9L4Q'><q id='z9L4Q'><span id='z9L4Q'><b id='z9L4Q'><form id='z9L4Q'><ins id='z9L4Q'></ins><ul id='z9L4Q'></ul><sub id='z9L4Q'></sub></form><legend id='z9L4Q'></legend><bdo id='z9L4Q'><pre id='z9L4Q'><center id='z9L4Q'></center></pre></bdo></b><th id='z9L4Q'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='z9L4Q'><tfoot id='z9L4Q'></tfoot><dl id='z9L4Q'><fieldset id='z9L4Q'></fieldset></dl></div>
      <tfoot id='z9L4Q'></tfoot>
        • <small id='z9L4Q'></small><noframes id='z9L4Q'>

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

            • <legend id='z9L4Q'><style id='z9L4Q'><dir id='z9L4Q'><q id='z9L4Q'></q></dir></style></legend>
              • 本文介紹了將 pandas.DataFrame 轉換為字節的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我需要將存儲在 pandas.DataFrame 中的數據轉換為字節字符串,其中每列可以具有單獨的數據類型(整數或浮點數).這是一組簡單的數據:

                I need convert the data stored in a pandas.DataFrame into a byte string where each column can have a separate data type (integer or floating point). Here is a simple set of data:

                df = pd.DataFrame([ 10, 15, 20], dtype='u1', columns=['a'])
                df['b'] = np.array([np.iinfo('u8').max, 230498234019, 32094812309], dtype='u8')
                df['c'] = np.array([1.324e10, 3.14159, 234.1341], dtype='f8')
                

                df 看起來像這樣:

                    a            b                  c
                0   10  18446744073709551615    1.324000e+10
                1   15  230498234019            3.141590e+00
                2   20  32094812309             2.341341e+02
                

                DataFrame 知道每一列 df.dtypes 的類型,所以我想做這樣的事情:

                The DataFrame knows about the types of each column df.dtypes so I'd like to do something like this:

                data_to_pack = [tuple(record) for _, record in df.iterrows()]
                data_array = np.array(data_to_pack, dtype=zip(df.columns, df.dtypes))
                data_bytes = data_array.tostring()
                

                這通常可以正常工作,但在這種情況下(由于 df['b'][0] 中存儲的最大值.上面的第二行將元組數組轉換為 具有給定類型集的 np.array 會導致以下錯誤:

                This typically works fine but in this case (due to the maximum value stored in df['b'][0]. The second line above converting the array of tuples to an np.array with a given set of types causes the following error:

                OverflowError: Python int too large to convert to C long
                

                第一行中的錯誤結果(我相信)將記錄提取為具有單一數據類型(默認為 float64)的 Series 和在float64 的最大 uint64 值不能直接轉換回 uint64.

                The error results (I believe) in the first line which extracts the record as a Series with a single data type (defaults to float64) and the representation chosen in float64 for the maximum uint64 value is not directly convertible back to uint64.

                1) 由于 DataFrame 已經知道每一列的類型,因此有辦法繞過創建一行元組以輸入到類型化的 numpy.array 構造函數中?或者有沒有比上面概述的更好的方法來保存這種轉換中的類型信息?

                1) Since the DataFrame already knows the types of each column is there a way to get around creating a row of tuples for input into the typed numpy.array constructor? Or is there a better way than outlined above to preserve the type information in such a conversion?

                2) 有沒有辦法直接從 DataFrame 到使用每列的類型信息表示數據的字節字符串.

                2) Is there a way to go directly from DataFrame to a byte string representing the data using the type information for each column.

                推薦答案

                可以使用df.to_records() 將您的數據幀轉換為 numpy recarray,然后調用 .tostring() 到將其轉換為字節串:

                You can use df.to_records() to convert your dataframe to a numpy recarray, then call .tostring() to convert this to a string of bytes:

                rec = df.to_records(index=False)
                
                print(repr(rec))
                # rec.array([(10, 18446744073709551615, 13240000000.0), (15, 230498234019, 3.14159),
                #  (20, 32094812309, 234.1341)], 
                #           dtype=[('a', '|u1'), ('b', '<u8'), ('c', '<f8')])
                
                s = rec.tostring()
                rec2 = np.fromstring(s, rec.dtype)
                
                print(np.all(rec2 == rec))
                # True
                

                這篇關于將 pandas.DataFrame 轉換為字節的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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時顯示進度條?)
                <legend id='gKKRj'><style id='gKKRj'><dir id='gKKRj'><q id='gKKRj'></q></dir></style></legend>

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

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

                        <tbody id='gKKRj'></tbody>
                    1. <tfoot id='gKKRj'></tfoot>

                          主站蜘蛛池模板: 国产精品毛片一区二区在线看 | 99久久日韩精品免费热麻豆美女 | 伊人网综合在线观看 | 欧美中文一区 | 久久久久久高潮国产精品视 | 国产一区二区成人 | 精品国产乱码久久久久久蜜柚 | 日韩免费在线观看视频 | 国产一区久久 | 欧美一级三级 | 中文字幕在线观看一区二区 | 色999日韩 | av网站在线免费观看 | 亚洲成人精选 | 婷婷久久精品一区二区 | www九色 | 欧美成人精品在线观看 | 日韩欧美中文字幕在线观看 | 中文字幕精品一区二区三区精品 | 国产精品爱久久久久久久 | 成人午夜免费网站 | 国家一级黄色片 | 国产成人精品一区二区 | 一级黄色毛片 | 日韩精品在线一区 | 亚洲高清视频在线观看 | 欧美视频免费在线 | 中文字幕在线播放第一页 | 国产高清性xxxxxxxx | 精品免费视频 | 七七婷婷婷婷精品国产 | 久久99精品久久久久久国产越南 | 午夜精品一区二区三区在线观看 | 亚洲精彩视频在线观看 | 亚洲乱码一区二区三区在线观看 | 国产一二区免费视频 | 日日操夜夜干 | 一级黄色大片 | 亚洲精彩视频 | 国产乱码精品一品二品 | 亚洲欧美在线一区 |