• <tfoot id='DSHGG'></tfoot>

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

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

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

        <bdo id='DSHGG'></bdo><ul id='DSHGG'></ul>
      1. NumPy 或 Pandas:将数组类型保持为整数,同时具有

        时间:2023-08-04
        • <tfoot id='TN6uh'></tfoot>

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

                <bdo id='TN6uh'></bdo><ul id='TN6uh'></ul>
                  <tbody id='TN6uh'></tbody>
                • <small id='TN6uh'></small><noframes id='TN6uh'>

                  本文介绍了NumPy 或 Pandas:将数组类型保持为整数,同时具有 NaN 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  是否有一种首选方法可以将 numpy 数组的数据类型固定为 int (或 int64 或其他),同时仍然里面有一个元素列为 numpy.NaN?

                  Is there a preferred way to keep the data type of a numpy array fixed as int (or int64 or whatever), while still having an element inside listed as numpy.NaN?

                  特别是,我正在将内部数据结构转换为 Pandas DataFrame.在我们的结构中,我们有仍然有 NaN 的整数类型列(但列的 dtype 是 int).如果我们将其设为 DataFrame,似乎会将所有内容重铸为浮点数,但我们真的很想成为 int.

                  In particular, I am converting an in-house data structure to a Pandas DataFrame. In our structure, we have integer-type columns that still have NaN's (but the dtype of the column is int). It seems to recast everything as a float if we make this a DataFrame, but we'd really like to be int.

                  想法?

                  尝试过的事情:

                  我尝试使用 pandas.DataFrame 下的 from_records() 函数和 coerce_float=False 但这没有帮助.我还尝试使用 NumPy 掩码数组和 NaN fill_value,这也不起作用.所有这些都导致列数据类型变为浮点数.

                  I tried using the from_records() function under pandas.DataFrame, with coerce_float=False and this did not help. I also tried using NumPy masked arrays, with NaN fill_value, which also did not work. All of these caused the column data type to become a float.

                  推荐答案

                  此功能已添加到 pandas(从 0.24 版本开始):https://pandas.pydata.org/pandas-docs/version/0.24/whatsnew/v0.24.0.html#optional-integer-na-support

                  This capability has been added to pandas (beginning with version 0.24): https://pandas.pydata.org/pandas-docs/version/0.24/whatsnew/v0.24.0.html#optional-integer-na-support

                  此时,它需要使用扩展dtype Int64(大写),而不是默认dtype int64(小写).

                  At this point, it requires the use of extension dtype Int64 (capitalized), rather than the default dtype int64 (lowercase).

                  这篇关于NumPy 或 Pandas:将数组类型保持为整数,同时具有 NaN 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 PyQt5 GUI 中制作快速 matplotlib 实时绘图 下一篇:如何在 Python 中将带点和逗号的字符串转换为浮点

                  相关文章

                  最新文章

                • <small id='3gOEP'></small><noframes id='3gOEP'>

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

                  <legend id='3gOEP'><style id='3gOEP'><dir id='3gOEP'><q id='3gOEP'></q></dir></style></legend>
                  1. <tfoot id='3gOEP'></tfoot>