<jupyter_start><jupyter_text>Following Notebook is part of notes made from Data Analysis To get started with pandas, you will need to get comfortable with its two workhorsedata structures: Series and DataFrame. While they are not a universal solution forevery problem, they provide a solid, easy-to-use basis for most applications.  Series A Series is a one-dimensional array-like object containing a sequence of values (ofsimilar types to NumPy types) and an associated array of data labels, called its index.The simplest Series is formed from only an array of data:<jupyter_code>import pandas as pd
import numpy as np
obj = pd.Series([4, 7, -5, 3])
obj
obj.values
obj.index # like range(4)<jupyter_output><empty_output><jupyter_text>Often it will be desirable to create a Series with an index identifying each data pointwith a label:<jupyter_code>obj2 = pd.Series([4, 7, -5, 3], index=['d', 'b', 'a', 'c'])
obj2.index<jupyter_output><empty_output><jupyter_text>Compared with NumPy arrays, you can use labels in the index when selecting singlevalues or a set of values:<jupyter_code>obj2['a']
obj2['d'] = 6
obj2[['c', 'a', 'd']]<jupyter_output><empty_output><jupyter_text>Here ['c', 'a', 'd'] is interpreted as a list of indices, even though it containsstrings instead of integers.Using NumPy functions or NumPy-like operations, such as filtering with a booleanarray, scalar multiplication, or applying math functions, will preserve the index-valuelink:<jupyter_code>obj2[obj2 > 0]
obj2 * 2
np.exp(obj2)<jupyter_output><empty_output><jupyter_text>Another way to think about a Series is as a fixed-length, ordered dict, as it is a map‐ping of index values to data values. It can be used in many contexts where you mightuse a dict:<jupyter_code>'b' in obj2
'e' in obj2<jupyter_output><empty_output><jupyter_text>Should you have data contained in a Python dict, you can create a Series from it bypassing the dict:<jupyter_code>sdata = {'Ohio': 35000, 'Texas': 71000, 'Oregon': 16000, 'Utah': 5000}
obj3 = pd.Series(sdata)
obj3<jupyter_output><empty_output><jupyter_text>When you are only passing a dict, the index in the resulting Series will have the dict’skeys in sorted order. You can override this by passing the dict keys in the order youwant them to appear in the resulting Series:<jupyter_code>states = ['California', 'Ohio', 'Oregon', 'Texas']
obj4 = pd.Series(sdata, index=states)
obj4
pd.isnull(obj4)
pd.notnull(obj4)<jupyter_output><empty_output><jupyter_text>Series also has these as instance methods:<jupyter_code>obj4.isnull()<jupyter_output><empty_output><jupyter_text>A useful Series feature for many applications is that it automatically aligns by indexlabel in arithmetic operations:<jupyter_code>obj3
obj4
obj3 + obj4
obj4.name = 'population'
obj4.index.name = 'state'
obj4<jupyter_output><empty_output><jupyter_text>A Series’s index can be altered in-place by assignment:<jupyter_code>obj
obj.index = ['Bob', 'Steve', 'Jeff', 'Ryan']
obj<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09547738693467336, 'fraction_numerical': 0.018760469011725293, 'mean_word_length': 6.446384039900249, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '249210', 'license': 'MIT', 'n_tokens_mistral': 993, 'n_tokens_neox': 941, 'n_words': 355, 'path': 'Pandas/.ipynb_checkpoints/pandas_notes-checkpoint.ipynb', 'repo_name': 'piszewc/python-deep-learning-data-science', 'size': '2985'}