當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。