<jupyter_start><jupyter_text>Functions<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# N_largest finds the items (i.e. rows) in a dafaframe corresponding to the n largest values of feature 'feature'

def N_largest (df,n,feature):
    return df.nlargest(n,feature)[list(df.columns[:4])+[feature]]
# N_smallest finds the items (i.e. rows) in a dafaframe corresponding to the n smallest values of feature 'feature'

def N_smallest (df,n,feature):
    return df.nsmallest(n,feature)[list(df.columns[:4])+[feature]]
# number_of_greater_a finds the number of items in a dataframe with feature 'feature'>a

def number_of_greater_a (df,feature,a):
    return len(df[df[feature]>a])
# number_of_greater_a finds the number of items in a dataframe with feature 'feature'<a

def number_of_smaller_a (df,feature,a):
    return len(df[df[feature]<a])
# n food items in the category 'FoodGroup' with lowest level of 'feature'

def N_nonzero_smallest(df,n,feature,food_group):
    aux_df = pd.DataFrame()
    aux_df = df[(df[feature] != 0) & (df['FoodGroup'] == food_group)]
    return N_smallest(aux_df,n,feature)
# remove_unit removes the units of all features (used in the dataframes in the project)

def remove_unit (str_list):
    aux_list=[]
    for element in str_list:
        aux_list.append(element.split('_')[0])
    return aux_list
# The 'Lin_Reg' function finds the least square regression line for the two lists 'Lone' and 'Ltwo'. Parameter 'c'
# specifies the color of the regression line.

def Lin_Reg(Lone,Ltwo,c):
    a=np.polyfit(Lone,Ltwo,1)
    y=lambda x: a[0]*x+a[1]
    b=np.linspace(min(Lone),max(Lone),200)
    return plt.plot(b,y(b),color=c)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11802325581395348, 'fraction_numerical': 0.005813953488372093, 'mean_word_length': 5.258181818181818, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '407984', 'license': 'MIT', 'n_tokens_mistral': 616, 'n_tokens_neox': 602, 'n_words': 174, 'path': 'Assignments/Final-Project/functions.ipynb', 'repo_name': 'masoudsoroush/UMBC_Data601', 'size': '1720'}