<jupyter_start><jupyter_text>*This notebook contains an excerpt from the [Python Data Science Handbook](http://shop.oreilly.com/product/0636920034919.do) by <NAME>; the content is available [on GitHub](https://github.com/jakevdp/PythonDataScienceHandbook).*  Introducing Pandas Objects<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>The Pandas Series ObjectA Pandas ``Series`` is a one-dimensional array of indexed data.It can be created from a list or array as follows:<jupyter_code>data = pd.Series([0.25, 0.5, 0.75, 1.0])
data
data.values<jupyter_output><empty_output><jupyter_text>The ``index`` is an array-like object of type ``pd.Index``, which we'll discuss in more detail momentarily.<jupyter_code>data.index
data
data[1]
data[1:3]
data = pd.Series([0.25, 0.5, 0.75, 1.0],
                 index=['a', 'b', 'c', 'd'])
data
data['b']
data['a']
data = pd.Series([0.25, 0.5, 0.75, 1.0],
                 index=[2, 5, 3, 7])
data
data.index
data[5]
population_dict = {'California': 38332521,
                   'Texas': 26448193,
                   'New York': 19651127,
                   'Florida': 19552860,
                   'Illinois': 12882135}
population = pd.Series(population_dict)
population<jupyter_output><empty_output><jupyter_text>By default, a ``Series`` will be created where the index is drawn from the sorted keys.From here, typical dictionary-style item access can be performed:<jupyter_code>population['California']
population_dict['California']
population['Texas':'Illinois']
#population_dict['Texas':'Illinois']<jupyter_output><empty_output><jupyter_text>The Pandas DataFrame Object<jupyter_code>area_dict = {'California': 423967, 'Texas': 695662, 'New York': 141297,
             'Florida': 170312, 'Illinois': 149995}
area = pd.Series(area_dict)
area
states = pd.DataFrame({'population': population,
                       'area': area})
states
type(states)
states.index
states.columns
states['area']
states['population']<jupyter_output><empty_output><jupyter_text>The Pandas Index ObjectWe have seen here that both the ``Series`` and ``DataFrame`` objects contain an explicit *index* that lets you reference and modify data.<jupyter_code>ind = pd.Index([2, 3, 5, 5, 7, 11])
ind
ind[1]
ind[::2]<jupyter_output><empty_output><jupyter_text>Index as ordered setPandas objects are designed to facilitate operations such as joins across datasets, which depend on many aspects of set arithmetic.The ``Index`` object follows many of the conventions used by Python's built-in ``set`` data structure, so that unions, intersections, differences, and other combinations can be computed in a familiar way:<jupyter_code>indA = pd.Index([1, 3, 5, 7, 9])
indB = pd.Index([2, 3, 5, 7, 11])
indA & indB  # intersection
indA | indB  # union
indA ^ indB  # symmetric difference<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12825017568517216, 'fraction_numerical': 0.04954321855235418, 'mean_word_length': 4.870103092783505, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 1, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '462605', 'license': 'MIT', 'n_tokens_mistral': 1043, 'n_tokens_neox': 904, 'n_words': 269, 'path': '14-introduction_dataframe_and_series.ipynb', 'repo_name': 'hanisaf/advanced-data-management-and-analytics', 'size': '2855'}