<jupyter_start><jupyter_text>Pandas Operations<jupyter_code>import pandas as pd
df = pd.DataFrame({'col1':[1,2,3,4],'col2':[444,555,666,444],'col3':['abc','def','ghi','xyz']})
df.head()
df<jupyter_output><empty_output><jupyter_text>Unique Values<jupyter_code>df['col2'].nunique()
df['col2'].unique()<jupyter_output><empty_output><jupyter_text>Selecting Data<jupyter_code>df[df['col1'] > 2]<jupyter_output><empty_output><jupyter_text>Custom functions<jupyter_code>def times2(x):
    return x * 2

df['col1'].apply(times2)
df['col1'].apply(lambda x: x * 2)<jupyter_output><empty_output><jupyter_text>Sorting<jupyter_code>df.columns
df.index
df.sort_values('col2')<jupyter_output><empty_output><jupyter_text>Null Value Check<jupyter_code>df.isnull()<jupyter_output><empty_output><jupyter_text>Pivot<jupyter_code>data = {'A':['foo','foo','foo','bar','bar','bar'],
     'B':['one','one','two','two','one','one'],
       'C':['x','y','x','y','x','y'],
       'D':[1,3,2,5,4,1]}

df = pd.DataFrame(data)
df
df.pivot_table(values='D',index=['A', 'B'],columns=['C'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23827046918123276, 'fraction_numerical': 0.03311867525298988, 'mean_word_length': 12.772151898734178, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '242857', 'license': 'Apache-2.0', 'n_tokens_mistral': 486, 'n_tokens_neox': 470, 'n_words': 36, 'path': 'pandas/PandasOperations.ipynb', 'repo_name': 'data-science-tsb/python-libraries', 'size': '1087'}