<jupyter_start><jupyter_text>Creating a Pipeline in Pandas<jupyter_code>import pandas as pd
# create an empty dataframe
df = pd.DataFrame()

# create a column
df['name'] = ['Damian', 'Sarah', 'Ray']
df['employed'] = ['Yes', 'Yes', 'No']
df['age'] = [32,39,19]

# view dataframe
df
# create a function
def mean_age_by_group(dataframe, col):
    # group the data by column and return the mean age per group
    return dataframe.groupby(col).mean()
# create a function 
def uppercase_column_name(dataframe):
    # capitalise all column headers
    dataframe.columns = dataframe.columns.str.upper()
    
    # return dataframe
    return dataframe
# create a pipeline that applies both functions
(df.pipe(mean_age_by_group, col='employed')
    # then apply the uppercase function 
    .pipe(uppercase_column_name)
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11296076099881094, 'fraction_numerical': 0.007134363852556481, 'mean_word_length': 4.767123287671233, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '13578', 'license': 'MIT', 'n_tokens_mistral': 283, 'n_tokens_neox': 271, 'n_words': 81, 'path': 'Creating Pandas Pipeline.ipynb', 'repo_name': 'mikelimqs/pandas-pipeline-easy-example', 'size': '841'}