<jupyter_start><jupyter_text>Filters & Multivalue Columns<jupyter_code>import numpy as np
import pandas as pd
data = pd.read_csv("data.csv")
data.head()<jupyter_output><empty_output><jupyter_text>Filtering by row or column index<jupyter_code>data.filter(items=["Item", "Unit"]).head()
data.filter(regex='^R').head()
data.filter(like='it').head()<jupyter_output><empty_output><jupyter_text>Same rules for index when axis 0 is specified<jupyter_code>data.filter(items=[0,3,5], axis=0)<jupyter_output><empty_output><jupyter_text>Dealing with multivalue columns<jupyter_code>import random
x = [[random.randrange(1,10) for a in range(5)] for b in range(10)]
x
names = "<NAME>"
df = pd.DataFrame({"Name" : names.split(), "Sales" : x})
df<jupyter_output><empty_output><jupyter_text>To simply split<jupyter_code>df2 = pd.DataFrame(df['Sales'].values.tolist(), columns=['May', 'June', 
                                                         'July', 'August', 'Sept'])
df2<jupyter_output><empty_output><jupyter_text>Alternative method<jupyter_code>pd.concat([df['Sales'].apply(pd.Series), df["Name"]], axis=1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16622458001768348, 'fraction_numerical': 0.01237842617152962, 'mean_word_length': 6.546666666666667, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '509090', 'license': 'MIT', 'n_tokens_mistral': 423, 'n_tokens_neox': 408, 'n_words': 65, 'path': 'Section 3/Code/3.2-Filters_Splitting_Multivalue_columns.ipynb', 'repo_name': 'PacktPublishing/Pandas-and-NumPy-Tips-Trick-and-Techniques', 'size': '1175'}