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 certain data types, Pandas extends NumPy's type system. String aliases for these types can be found in dtypes.
Pandas Array
| Class/Method | Description |
|---|---|
pd.array(data, dtype) |
Create a Pandas array (ExtensionArray)。 |
pd.Series.array |
Return the underlying array of a Series (ExtensionArray)。 |
pd.arrays.IntegerArray |
Array for storing integer data (supports missing values). |
pd.arrays.BooleanArray |
Array for storing boolean data (supports missing values). |
pd.arrays.StringArray |
Array for storing string data (supports missing values). |
pd.arrays.IntervalArray |
Array for storing interval data. |
pd.arrays.DatetimeArray |
Array for storing datetime data. |
pd.arrays.TimedeltaArray |
Array for storing timedelta data. |
pd.arrays.PeriodArray |
Array for storing period data. |
pd.arrays.SparseArray |
Array for storing sparse data. |
Pandas Scalar
| Class/Method | Description |
|---|---|
pd.NA |
Scalar representing missing values (similar toNaN)。 |
pd.Timestamp |
Scalar representing timestamps. |
pd.Timedelta |
Scalar representing time differences. |
pd.Period |
Scalar representing periods. |
pd.Interval |
Scalar representing intervals. |
pd.Categorical |
Scalar representing categorical data. |
Pandas Data Types
| Class/Method | 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 float data type (supports missing values). |
pd.Float64Dtype() |
64-bit float data type (supports missing values). |
pd.CategoricalDtype() |
Categorical data type. |
pd.DatetimeTZDtype() |
Datetime data type with timezone. |
pd.PeriodDtype() |
Period data type. |
pd.IntervalDtype() |
Interval data type. |
pd.SparseDtype() |
Sparse data type. |
Common Methods
Array Methods
| Method | Description |
|---|---|
array.take(indices) |
Extract elements from an array based on indices. |
array.copy() |
Copy the array. |
array.isna() |
Check for missing values in the array. |
array.fillna(value) |
Fill missing values with a specified value. |
array.unique() |
Return unique values in the array. |
array.value_counts() |
Return the frequency of each value in the array. |
Scalar Methods
| Method | Description |
|---|---|
timestamp.to_pydatetime() |
willTimestampConvert to Python'sdatetimeobject. |
timedelta.total_seconds() |
willTimedeltaConvert to total seconds. |
period.start_time |
ReturnPeriodthe start time of |
period.end_time |
ReturnPeriodthe end time of |
interval.left |
ReturnIntervalthe left boundary of |
interval.right |
ReturnIntervalthe right boundary of |
Data Type Methods
| Method | Description |
|---|---|
dtype.name |
Return the name of the data type. |
dtype.kind |
Return the kind of the data type (e.g.,imeans integer,fmeans float). |
dtype.construct_array_type() |
Return the array class associated with the data type. |
Examples
import pandas as pd
# Create a Pandas array
arr = pd.array([1, 2, None], dtype=pd.Int64Dtype())
print(arr)
# Use Pandas scalar
ts = pd.Timestamp('2023-01-01')
print(ts.year) # Output the year
# Use Pandas data type
dtype = pd.StringDtype()
print(dtype.name) # Output data type name
# Create a Pandas array
arr = pd.array([1, 2, None], dtype=pd.Int64Dtype())
print(arr)
# Use Pandas scalar
ts = pd.Timestamp('2023-01-01')
print(ts.year) # Output the year
# Use Pandas data type
dtype = pd.StringDtype()
print(dtype.name) # Output data type name
For more detailed information, please refer toPandas official documentation。
Other Extensions