4.3. Series Dtypes
Data Types
DType Attribute
4.3.1. SetUp
>>> import pandas as pd
4.3.2. Numeric
int64
float64
complex128
object
4.3.3. String
string
object
4.3.4. Date
datetime64
object
4.3.5. Astype
4.3.6. Convert Dtypes
>>> s = pd.Series(['a', 'b', 'c', 'd'])
>>> s
0 a
1 b
2 c
3 d
dtype: object
>>>
>>> s.convert_dtypes()
0 a
1 b
2 c
3 d
dtype: string
>>> s = pd.Series(['a', 'b', None, 'd'])
>>> s
0 a
1 b
2 None
3 d
dtype: object
>>>
>>> s.convert_dtypes()
0 a
1 b
2 <NA>
3 d
dtype: string
>>> s = pd.Series([1, 2, 3, 4])
>>> s
0 1
1 2
2 3
3 4
dtype: int64
>>>
>>> s.convert_dtypes()
0 1
1 2
2 3
3 4
dtype: Int64
>>> s = pd.Series([1, 2, None, 4])
>>> s
0 1.0
1 2.0
2 NaN
3 4.0
dtype: float64
>>>
>>> s.convert_dtypes()
0 1
1 2
2 <NA>
3 4
dtype: Int64