Pandas Array/Scalar/Data Type Reference Manual
For most data types, Pandas uses NumPy arrays as the concrete storage objects, which are contained in Index, Series, or DataFrame.
For some data types, Pandas extends NumPy's type system. The string aliases of these types can be found in dtypes.
Pandas arrays
| Classes/methods | Description |
|---|---|
pd.array(data, dtype) |
Create a Pandas array (ExtensionArray)。 |
pd.Series.array |
Return the underlying array of a Series (ExtensionArray)。 |
pd.arrays.IntegerArray |
An array for storing integer data (supports missing values). |
pd.arrays.BooleanArray |
An array for storing boolean data (supports missing values). |
pd.arrays.StringArray |
An array for storing string data (supports missing values). |
pd.arrays.IntervalArray |
An array for storing interval data. |
pd.arrays.DatetimeArray |
An array for storing datetime data. |
pd.arrays.TimedeltaArray |
An array for storing timedelta data. |
pd.arrays.PeriodArray |
An array for storing period data. |
pd.arrays.SparseArray |
An array for storing sparse data. |
Pandas scalars
| Classes/methods | Description |
|---|---|
pd.NA |
A scalar representing a missing value (similar to NaN)。 |
pd.Timestamp |
A scalar representing a timestamp. |
pd.Timedelta |
A scalar representing a time difference. |
pd.Period |
A scalar representing a period. |
pd.Interval |
A scalar representing an interval. |
pd.Categorical |
A scalar representing categorical data. |
Pandas data types
| Classes/methods | Description |
|---|---|
pd.StringDtype() |
String data type (supports missing values). |
pd.BooleanDtype() |
Boolean data type (supports missing values). |
pd.Int8Dtype() |
8-bit integer data type (supports missing values). |
pd.Int16Dtype() |
16-bit integer data type (supports missing values). |
pd.Int32Dtype() |
32-bit integer data type (supports missing values). |
pd.Int64Dtype() |
64-bit integer data type (supports missing values). |
pd.Float32Dtype() |
32-bit floating-point data type (supports missing values). |
pd.Float64Dtype() |
64-bit floating-point data type (supports missing values). |
pd.CategoricalDtype() |
Categorical data type. |
pd.DatetimeTZDtype() |
Timezone-aware datetime data type. |
pd.PeriodDtype() |
Period data type. |
pd.IntervalDtype() |
Interval data type. |
pd.SparseDtype() |
Sparse data type. |
// 2022-01-01 00:00:00 GMT
Array methods
| Method | Description |
|---|---|
array.take(indices) |
Extract elements from an array by index. |
array.copy() |
Copy an array. |
array.isna() |
Check for missing values in an array. |
array.fillna(value) |
Fill missing values with a specified value. |
array.unique() |
Return the unique values in an array. |
array.value_counts() |
Return the frequency of each value in an array. |
Scalar methods
| Method | Description |
|---|---|
timestamp.to_pydatetime() |
data to the child component via Timestamp Convert to Python's datetime object. |
timedelta.total_seconds() |
data to the child component via Timedelta Convert to total seconds. |
period.start_time |
Return Period The start time of |
period.end_time |
Return Period The end time of |
interval.left |
Return Interval The left bound of |
interval.right |
Return Interval The right bound of |
Data type methods
| Method | Description |
|---|---|
dtype.name |
Return the name of the data type. |
dtype.kind |
Return the kind of the data type (such as i for integer,f for floating point). |
dtype.construct_array_type() |
Return the array class associated with the data type. |
Example
import
pandas
as
pd
Create Pandas arrays
arr
=
pd.
array
(
[
1
,
2
,
None
]
,
dtype
=
pd.
Int64Dtype
(
)
)
(
arr
)
Use Pandas scalars
ts
=
pd.
Timestamp
(
'2023-01-01'
)
(
ts.
year
)
Output the year
Use Pandas data types
dtype
=
pd.
StringDtype
(
)
(
dtype.
name
)
Output the data type name
For more detailed information, refer to Pandas official documentation。