<jupyter_start><jupyter_text>`cyberpandas` provides a container, `IPArray` for holding IP Address data.This array can efficiently process large arrays of IPv4 and IPv6 addresses.It satisfies pandas' extension array interface, so these arrays can be used inside a pandas Series or DataFrame, just like a regular NumPy array.`cyberpandas` also registers the `.ip` accessor on `pandas.Series` for accessing IP-related properties and methods on a Series with IP Address data.<jupyter_code>import ipaddress

import numpy as np
import pandas as pd

import cyberpandas<jupyter_output><empty_output><jupyter_text>Creating ArraysAN `IPArray` can be created from many sources with the `cyberpandas.to_ipaddress` parser: From strings<jupyter_code>cyberpandas.to_ipaddress([
    '0.0.0.0',
    '192.168.1.1',
    '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
])<jupyter_output><empty_output><jupyter_text>From integers<jupyter_code>cyberpandas.to_ipaddress([
    0,
    3232235777,
    42540766452641154071740215577757643572
])<jupyter_output><empty_output><jupyter_text>From bytes<jupyter_code>cyberpandas.to_ipaddress([
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0\xa8\x01\x01',
    b' \x01\r\xb8\x85\xa3\x00\x00\x00\x00\x8a.\x03ps4',
])<jupyter_output><empty_output><jupyter_text>From integers<jupyter_code>values = cyberpandas.to_ipaddress([
    0,
    3232235777,
    42540766452641154071740215577757643572
])
values<jupyter_output><empty_output><jupyter_text>Pandas Integration Our `IPArray` array can be stored in pandas' containers.<jupyter_code>s = pd.Series(values)
s
df = pd.DataFrame({
    "A": [np.nan, 2, 3],
    "B": values
})
df<jupyter_output><empty_output><jupyter_text>Most pandas methods will work with `IPAddress` data. Indexing<jupyter_code>df.loc[[0, 1], 'B']
df.loc[2, 'B']<jupyter_output><empty_output><jupyter_text>Concatenation:<jupyter_code>pd.concat([df, df], ignore_index=True)<jupyter_output><empty_output><jupyter_text>Missing data<jupyter_code>df.isna()
df.dropna(subset=['B'])<jupyter_output><empty_output><jupyter_text>Groupby<jupyter_code>df = pd.DataFrame({
    "A": np.random.uniform(size=100),
    "B": cyberpandas.IPArray(
        np.random.choice(['192.168.1.1',
                          '192.168.1.2',
                          '192.168.1.10'],
                             size=100).tolist()),
    "C": np.random.normal(size=100),
})
df.groupby("B").agg({"A": 'count', 'C': 'mean'})<jupyter_output><empty_output><jupyter_text>Accessor`cyberpandas` registers the `.ip` accessor with pandas `Series`.With this accessor, you can access many IP-address-specific attributes and methods, similar to `.dt` and `.cat` for datetime and categorical data.<jupyter_code>df.B.ip.is_ipv4.head()
df.B.ip.isna.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1374340949033392, 'fraction_numerical': 0.09103690685413006, 'mean_word_length': 5.146868250539957, 'pattern_counts': {'":': 6, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '470599', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1113, 'n_words': 190, 'path': 'ip-address.ipynb', 'repo_name': 'achapkowski/cyberpandas', 'size': '2845'}