<jupyter_start><jupyter_text>Nullable integer data type>**Note**>>IntegerArray is currently experimental. Its API or implementation maychange without warning.Changed in version 1.0.0: Now uses `pandas.NA` as the missing value ratherthan `numpy.nan`.In missing_data, we saw that pandas primarily uses `NaN` to representmissing data. Because `NaN` is a float, this forces an array of integers withany missing values to become floating point. In some cases, this may not mattermuch. But if your integer column is, say, an identifier, casting to float canbe problematic. Some integers cannot even be represented as floating pointnumbers.  Constructionpandas can represent integer data with possibly missing values using`arrays.IntegerArray`. This is an extension typesimplemented within pandas.<jupyter_code>arr = pd.array([1, 2, None], dtype=pd.Int64Dtype())
arr<jupyter_output><empty_output><jupyter_text>Or the string alias `"Int64"` (note the capital `"I"`, to differentiate fromNumPy’s `'int64'` dtype:<jupyter_code>pd.array([1, 2, np.nan], dtype="Int64")<jupyter_output><empty_output><jupyter_text>All NA-like values are replaced with `pandas.NA`.<jupyter_code>pd.array([1, 2, np.nan, None, pd.NA], dtype="Int64")<jupyter_output><empty_output><jupyter_text>This array can be stored in a `DataFrame` or `Series` like anyNumPy array.<jupyter_code>pd.Series(arr)<jupyter_output><empty_output><jupyter_text>You can also pass the list-like object to the `Series` constructorwith the dtype.Currently `pandas.array()` and `pandas.Series()` use differentrules for dtype inference. `pandas.array()` will infer a nullable-integer dtype<jupyter_code>pd.array([1, None])
pd.array([1, 2])<jupyter_output><empty_output><jupyter_text>For backwards-compatibility, `Series` infers these as eitherinteger or float dtype<jupyter_code>pd.Series([1, None])
pd.Series([1, 2])<jupyter_output><empty_output><jupyter_text>We recommend explicitly providing the dtype to avoid confusion.<jupyter_code>pd.array([1, None], dtype="Int64")
pd.Series([1, None], dtype="Int64")<jupyter_output><empty_output><jupyter_text>In the future, we may provide an option for `Series` to infer anullable-integer dtype.  OperationsOperations involving an integer array will behave similar to NumPy arrays.Missing values will be propagated, and the data will be coerced to anotherdtype if needed.<jupyter_code>s = pd.Series([1, 2, None], dtype="Int64")

# arithmetic
s + 1
# comparison
s == 1
# indexing
s.iloc[1:3]
# operate with other dtypes
s + s.iloc[1:3].astype("Int8")
# coerce when needed
s + 0.01<jupyter_output><empty_output><jupyter_text>These dtypes can operate as part of `DataFrame`.<jupyter_code>df = pd.DataFrame({"A": s, "B": [1, 1, 3], "C": list("aab")})
df
df.dtypes<jupyter_output><empty_output><jupyter_text>These dtypes can be merged & reshaped & casted.<jupyter_code>pd.concat([df[["A"]], df[["B", "C"]]], axis=1).dtypes
df["A"].astype(float)<jupyter_output><empty_output><jupyter_text>Reduction and groupby operations such as ‘sum’ work as well.<jupyter_code>df.sum()
df.groupby("B").A.sum()<jupyter_output><empty_output><jupyter_text>Scalar NA Value`arrays.IntegerArray` uses `pandas.NA` as its scalarmissing value. Slicing a single element that’s missing will return`pandas.NA`<jupyter_code>a = pd.array([1, None], dtype="Int64")
a[1]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12615844544095664, 'fraction_numerical': 0.015844544095665172, 'mean_word_length': 7.282178217821782, 'pattern_counts': {'":': 3, '<': 49, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '202436', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1109, 'n_words': 319, 'path': '04_user_guide/31_Nullable_integer_na.ipynb', 'repo_name': 'olippuner/Pandas_Docu_as_Notebooks', 'size': '3345'}