4

I have a pandas Series with large integers as strings and Nones, and want to convert this to pandas Int64 (nullable integer) without precision loss. Casting to float (what e.g. pd.to_numeric does) leads to precision loss. What is a good way to do that?

E.g.

test_series = pd.Series(['4498465375688747025',
'4366843671738038466',
None,
None,
'4235221967816327545'])

test_series.astype('Int64') throws TypeError: object cannot be converted to an IntegerDtype on pandas 1.0.5

Florian
  • 41
  • 1
  • 2
    *pd.Series([int(x) if x else x for x in test_series], dtype=pd.Int64Dtype())* this works (see nullable integer in pandas doc) but I bet it is possible without list comprehension, looking into it – Ezer K Jul 30 '20 at 13:44

0 Answers0