0

I want to generate a pandas series with null values, with int type. I use this:

import pandas as pd
pd.Series(None, index=[1, 2, 3], dtype=int)

And it returns

1    0
2    0
3    0
dtype: int64

What can I do for it to return a series whose values are null?

David Masip
  • 2,146
  • 1
  • 26
  • 46

1 Answers1

3

Use Int64 for nullable integer type:

s = pd.Series(None, index=[1, 2, 3], dtype='Int64')
print (s)
1    <NA>
2    <NA>
3    <NA>
dtype: Int64

s = pd.Series(np.nan, index=[1, 2, 3], dtype=int)
print (s)
1   NaN
2   NaN
3   NaN
dtype: float64 <- casting to float
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252