4.2. Series Dtypes

  • Data Types

4.2.1. DType Attribute

4.2.2. Numeric

  • int64

  • float64

  • complex128

  • object

4.2.3. String

  • string

  • object

4.2.4. Date

  • datetime64

  • object

4.2.5. Astype

4.2.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