当前位置: 首页>>代码示例>>Python>>正文


Python pandas.array方法代码示例

本文整理汇总了Python中pandas.array方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.array方法的具体用法?Python pandas.array怎么用?Python pandas.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas的用法示例。


在下文中一共展示了pandas.array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_array_interface_tz

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_array_interface_tz(self):
        tz = "US/Central"
        data = DatetimeArray(pd.date_range('2017', periods=2, tz=tz))
        result = np.asarray(data)

        expected = np.array([pd.Timestamp('2017-01-01T00:00:00', tz=tz),
                             pd.Timestamp('2017-01-02T00:00:00', tz=tz)],
                            dtype=object)
        tm.assert_numpy_array_equal(result, expected)

        result = np.asarray(data, dtype=object)
        tm.assert_numpy_array_equal(result, expected)

        result = np.asarray(data, dtype='M8[ns]')

        expected = np.array(['2017-01-01T06:00:00',
                             '2017-01-02T06:00:00'], dtype="M8[ns]")
        tm.assert_numpy_array_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_datetimes.py

示例2: test_sanitize_string_dtype

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_sanitize_string_dtype():
    df = pd.DataFrame(
        {
            "string_object": ["a", "b", "c", "d"],
            "string_string": pd.array(["a", "b", "c", "d"], dtype="string"),
            "string_object_null": ["a", "b", None, "d"],
            "string_string_null": pd.array(["a", "b", None, "d"], dtype="string"),
        }
    )

    df_clean = sanitize_dataframe(df)
    assert {col.dtype.name for _, col in df_clean.iteritems()} == {"object"}

    result_python = {col_name: list(col) for col_name, col in df_clean.iteritems()}
    assert result_python == {
        "string_object": ["a", "b", "c", "d"],
        "string_string": ["a", "b", "c", "d"],
        "string_object_null": ["a", "b", None, "d"],
        "string_string_null": ["a", "b", None, "d"],
    } 
开发者ID:altair-viz,项目名称:altair,代码行数:22,代码来源:test_utils.py

示例3: test_sanitize_boolean_dtype

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_sanitize_boolean_dtype():
    df = pd.DataFrame(
        {
            "bool_none": pd.array([True, False, None], dtype="boolean"),
            "none": pd.array([None, None, None], dtype="boolean"),
            "bool": pd.array([True, False, True], dtype="boolean"),
        }
    )

    df_clean = sanitize_dataframe(df)
    assert {col.dtype.name for _, col in df_clean.iteritems()} == {"object"}

    result_python = {col_name: list(col) for col_name, col in df_clean.iteritems()}
    assert result_python == {
        "bool_none": [True, False, None],
        "none": [None, None, None],
        "bool": [True, False, True],
    } 
开发者ID:altair-viz,项目名称:altair,代码行数:20,代码来源:test_utils.py

示例4: add_facility_id_unit_id_epa

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def add_facility_id_unit_id_epa(df):
    """
    Harmonize columns that are added later.

    The datapackage validation checks for consistent column names, and these
    two columns aren't present before August 2008, so this adds them in.

    Args:
        df (pandas.DataFrame): A CEMS dataframe

    Returns:
        pandas.Dataframe: The same DataFrame guaranteed to have int facility_id
        and unit_id_epa cols.

    """
    if ("facility_id" not in df.columns) or ("unit_id_epa" not in df.columns):
        # Can't just assign np.NaN and get an integer NaN, so make a new array
        # with the right shape:
        na_col = pd.array(np.full(df.shape[0], np.NaN), dtype="Int64")
        if "facility_id" not in df.columns:
            df["facility_id"] = na_col
        if "unit_id_epa" not in df.columns:
            df["unit_id_epa"] = na_col
    return df 
开发者ID:catalyst-cooperative,项目名称:pudl,代码行数:26,代码来源:epacems.py

示例5: kind

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def kind(self) -> str:
        """Return a character code (one of 'biufcmMOSUV'), default 'O'.

        This should match the NumPy dtype used when the array is
        converted to an ndarray, which is probably 'O' for object if
        the extension type cannot be represented as a built-in NumPy
        type.

        See Also
        --------
        numpy.dtype.kind
        """
        if pa.types.is_date(self.arrow_dtype):
            return "O"
        else:
            return np.dtype(self.arrow_dtype.to_pandas_dtype()).kind 
开发者ID:xhochy,项目名称:fletcher,代码行数:18,代码来源:base.py

示例6: test_pandas_array

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_pandas_array(self, data):
        # pd.array(extension_array) should be idempotent...
        result = pd.array(data)
        self.assert_extension_array_equal(result, data) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:constructors.py

示例7: test_pandas_array_dtype

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_pandas_array_dtype(self, data):
        # ... but specifying dtype will override idempotency
        result = pd.array(data, dtype=np.dtype(object))
        expected = pd.arrays.PandasArray(np.asarray(data, dtype=object))
        self.assert_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:constructors.py

示例8: data_missing

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def data_missing(allow_in_pandas):
    return PandasArray(np.array([np.nan, (1,)])) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_numpy_nested.py

示例9: data_for_sorting

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def data_for_sorting(allow_in_pandas):
    """Length-3 array with a known sort order.

    This should be three items [B, C, A] with
    A < B < C
    """
    # Use an empty tuple for first element, then remove,
    # to disable np.array's shape inference.
    return PandasArray(
        np.array([(), (2,), (3,), (1,)])[1:]
    ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_numpy_nested.py

示例10: data_missing_for_sorting

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def data_missing_for_sorting(allow_in_pandas):
    """Length-3 array with a known sort order.

    This should be three items [B, NA, A] with
    A < B and NA missing.
    """
    return PandasArray(
        np.array([(1,), np.nan, (0,)])
    ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_numpy_nested.py

示例11: test_array_interface

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_array_interface(self, data):
        # NumPy array shape inference
        pass 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_numpy_nested.py

示例12: test_shift_fill_value

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_shift_fill_value(self, data):
        # np.array shape inference. Shift implementation fails.
        super().test_shift_fill_value(data) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_numpy_nested.py

示例13: test_fillna_copy_frame

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_fillna_copy_frame(self, data_missing):
        # The "scalar" for this array isn't a scalar.
        pass 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_numpy_nested.py

示例14: test_fillna_copy_series

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_fillna_copy_series(self, data_missing):
        # The "scalar" for this array isn't a scalar.
        pass 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_numpy_nested.py

示例15: test_array

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import array [as 别名]
def test_array(data, dtype, expected):
    result = pd.array(data, dtype=dtype)
    tm.assert_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:test_array.py


注:本文中的pandas.array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。