How to specify the type of pandas series elements in type hints?

后端 未结 2 1777
滥情空心
滥情空心 2021-02-20 01:04

My function returns a pandas series, where all elements have a specific type (say str). The following MWE should give an impression:

import pandas as         


        
相关标签:
2条回答
  • 2021-02-20 01:41

    Unfortunately Python's type hinting does not support this out of the shelf. Nonetheless, you can always make use of dataenforce library (link) to add hints or even enforce validation.

    0 讨论(0)
  • 2021-02-20 01:44

    You can specify using dtype parameter

    pd.Series(data, dtype=str) for more information click here

    0 讨论(0)
提交回复
热议问题