<jupyter_start><jupyter_text>![title](Header__0009_1.png "Header")___ Chapter 1 - Data Munging Basics Segment 1 - Filtering and selecting data<jupyter_code>import numpy as np
import pandas as pd

from pandas import Series, DataFrame<jupyter_output><empty_output><jupyter_text>Selecting and retrieving data<jupyter_code>series_obj = Series(np.arange(8), index=['row 1', 'row 2','row 3','row 4','row 5', 'row 6', 'row 7', 'row 8'])
series_obj
# ['label-index']
# ♔┈♔┈♔┈( WHAT THIS DOES ) ┈♔┈♔┈♔
# When you write square brackets with a label-index inside them, this tells Python to select and 
# retrieve all records with that label-index.
series_obj['row 7']
# [integer index] 
# ♔┈♔┈♔┈( WHAT THIS DOES )┈♔┈♔┈♔
# When you write square brackets with an integer index inside them, this tells Python to select and 
# retrieve all records with the specified integer index.
series_obj[[0,7]]
np.random.seed(25)
DF_obj = DataFrame(np.random.rand(36).reshape((6,6)), 
                   index=['row 1', 'row 2', 'row 3', 'row 4', 'row 5', 'row 6'],
                   columns=['column 1', 'column 2', 'column 3', 'column 4', 'column 5', 'column 6'])
DF_obj
# object_name.ix[[row indexes], [column indexes]]
# ♔┈♔┈♔┈( WHAT THIS DOES )┈♔┈♔┈♔
# When you call the .ix[] special indexer, and pass in a set of row and colum indexes, this tells 
# Python to select and retrieve only those specific rows and columns.
DF_obj.loc[['row 2', 'row 5'], ['column 5', 'column 2']]<jupyter_output><empty_output><jupyter_text>Data slicing<jupyter_code># ['starting label-index':'ending label-index'] 
# ♔┈♔┈♔┈( WHAT THIS DOES )┈♔┈♔┈♔
# Data slicing allows you to select and retrieve all records from the starting label-index, to the 
# ending label-index, and every record in between.
series_obj['row 3':'row 7']<jupyter_output><empty_output><jupyter_text>Comparing with scalars<jupyter_code># object_name < scalar value
# ♔┈♔┈♔┈( WHAT THIS DOES )┈♔┈♔┈♔
# You can use comparison operators (like greater than or less than) to return True / False values for 
# all records, to indicate how each element compares to a scalar value. 
DF_obj < .2<jupyter_output><empty_output><jupyter_text>Filtering with scalars<jupyter_code># object_name[object_name > scalar value] 
# ♔┈♔┈♔┈( WHAT THIS DOES )┈♔┈♔┈♔
# You can also use comparison operators and scalar values for indexing, to return only the records 
# that satisfy the comparison expression you write.
series_obj[series_obj > 6]<jupyter_output><empty_output><jupyter_text>Setting values with scalars<jupyter_code># ['label-index', 'label-index', 'label-index'] = scalar value
# ♔┈♔┈♔┈( WHAT THIS DOES )┈♔┈♔┈♔
# Setting is where you select all records associated with the specified label-indexes and set those 
# values equal to a scalar.
series_obj['row 1', 'row 5', 'row 8'] = 8
series_obj<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1397395283350933, 'fraction_numerical': 0.017247448081661388, 'mean_word_length': 5.287610619469026, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '140759', 'license': 'MIT', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1020, 'n_words': 333, 'path': 'Ch01/01_01/01_01.ipynb', 'repo_name': 'Sinclair-Seo/Python-for-Data-Science-Essential-Training-in-LinkedIn', 'size': '2841'}