I'm trying to convert an UInt8
pandas series into the new StringDtype
.
I can do the following, covered in this question, which predates the new string
dtype:
import pandas as pd
int_series = pd.Series(range(20), dtype="UInt8")
obj_series = int_series.apply(str)
Which gives me a series of Object dtype containing strings.
But if I try to convert the series to the new string
dtype, I get an error:
>>> string_series = int_series.astype("string")
...
TypeError: data type not understood
Note that the first converting the series to Object
and then to string
dtype works:
int_series.apply(str).astype("string")
How can I convert the int series to string directly?
I'm using pandas version 1.0.3 on Python 3.7.6
Update: I've found this open issue in the pandas Github page that describes the exact same problem.
A comment in the issue above points to another open issue which covers the desired but currently not available functionality of converting between different ExtensionArray types.
So the answer is that the direct conversion cannot be done now, but likely will be possible in the future.