本文整理汇总了Python中pandas.api.types.is_integer方法的典型用法代码示例。如果您正苦于以下问题:Python types.is_integer方法的具体用法?Python types.is_integer怎么用?Python types.is_integer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.api.types
的用法示例。
在下文中一共展示了types.is_integer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_conversions
# 需要导入模块: from pandas.api import types [as 别名]
# 或者: from pandas.api.types import is_integer [as 别名]
def test_conversions(data_missing):
# astype to object series
df = pd.DataFrame({'A': data_missing})
result = df['A'].astype('object')
expected = pd.Series(np.array([np.nan, 1], dtype=object), name='A')
tm.assert_series_equal(result, expected)
# convert to object ndarray
# we assert that we are exactly equal
# including type conversions of scalars
result = df['A'].astype('object').values
expected = np.array([np.nan, 1], dtype=object)
tm.assert_numpy_array_equal(result, expected)
for r, e in zip(result, expected):
if pd.isnull(r):
assert pd.isnull(e)
elif is_integer(r):
# PY2 can be int or long
assert r == e
assert is_integer(e)
else:
assert r == e
assert type(r) == type(e)
示例2: _random_state
# 需要导入模块: from pandas.api import types [as 别名]
# 或者: from pandas.api.types import is_integer [as 别名]
def _random_state(state=None):
"""
Helper function for processing random_state arguments.
Parameters
----------
state : int, np.random.RandomState, None.
If receives an int, passes to np.random.RandomState() as seed.
If receives an np.random.RandomState object, just returns object.
If receives `None`, returns np.random.
If receives anything else, raises an informative ValueError.
Default None.
Returns
-------
np.random.RandomState
"""
if types.is_integer(state):
return np.random.RandomState(state)
elif isinstance(state, np.random.RandomState):
return state
elif state is None:
return np.random
else:
raise ValueError("random_state must be an integer, a numpy "
"RandomState, or None")
示例3: get_meta
# 需要导入模块: from pandas.api import types [as 别名]
# 或者: from pandas.api.types import is_integer [as 别名]
def get_meta(
columns, dtype=None, index_columns=None, index_names=None, default_dtype=np.object
): # pragma: no cover
"""
Extracted and modified from pandas/io/parsers.py :
_get_empty_meta (BSD licensed).
"""
columns = list(columns)
# Convert `dtype` to a defaultdict of some kind.
# This will enable us to write `dtype[col_name]`
# without worrying about KeyError issues later on.
if not isinstance(dtype, dict):
# if dtype == None, default will be default_dtype.
dtype = defaultdict(lambda: dtype or default_dtype)
else:
# Save a copy of the dictionary.
_dtype = dtype.copy()
dtype = defaultdict(lambda: default_dtype)
# Convert column indexes to column names.
for k, v in six.iteritems(_dtype):
col = columns[k] if is_integer(k) else k
dtype[col] = v
if index_columns is None or index_columns is False:
index = pd.Index([])
else:
data = [pd.Series([], dtype=dtype[name]) for name in index_names]
if len(data) == 1:
index = pd.Index(data[0], name=index_names[0])
else:
index = pd.MultiIndex.from_arrays(data, names=index_names)
index_columns.sort()
for i, n in enumerate(index_columns):
columns.pop(n - i)
col_dict = {col_name: pd.Series([], dtype=dtype[col_name]) for col_name in columns}
return pd.DataFrame(col_dict, columns=columns, index=index)
示例4: _rename_chroms
# 需要导入模块: from pandas.api import types [as 别名]
# 或者: from pandas.api.types import is_integer [as 别名]
def _rename_chroms(grp, rename_dict, h5opts):
chroms = get(grp["chroms"]).set_index("name")
n_chroms = len(chroms)
new_names = np.array(
chroms.rename(rename_dict).index.values, dtype=CHROM_DTYPE
) # auto-adjusts char length
del grp["chroms/name"]
grp["chroms"].create_dataset(
"name", shape=(n_chroms,), dtype=new_names.dtype, data=new_names, **h5opts
)
bins = get(grp["bins"])
n_bins = len(bins)
idmap = dict(zip(new_names, range(n_chroms)))
if is_categorical(bins["chrom"]) or is_integer(bins["chrom"]):
chrom_ids = bins["chrom"].cat.codes
chrom_dtype = h5py.special_dtype(enum=(CHROMID_DTYPE, idmap))
del grp["bins/chrom"]
try:
grp["bins"].create_dataset(
"chrom", shape=(n_bins,), dtype=chrom_dtype, data=chrom_ids, **h5opts
)
except ValueError:
# If HDF5 enum header would be too large,
# try storing chrom IDs as raw int instead
chrom_dtype = CHROMID_DTYPE
grp["bins"].create_dataset(
"chrom", shape=(n_bins,), dtype=chrom_dtype, data=chrom_ids, **h5opts
)