Package: helper-funcs
This module provides a handful of functions to simplify the typical data processing operations and simplifying data verification procedures.Dependenciesnumpy 1.17.1pandas 0.25.1Installation Guidepip install helper-funcsUsageImport class "HF" from module "helper_funcs":from helper_funcs import HFAnd then call any of the methods described below.Methodsdf_preview(df, n_samples)DescriptionCreates a nice summary table of your DataFrame.Parametersdf: pandas.DataFrameThe DataFrame you want to create a preview for.n_samples: int, optional (default = 2)Number of unique values from each column to be displayed.Returnspandas.DataFrame containing the summary information about the passed DataFrame.rename_col(df, old_name, new_name)DescriptionRenames the specified column.Parametersdf: pandas.DataFrameThe DataFrame you want to create a preview for.old_name: strName of existingdfcolumn to be renamed.new_name: strName which will replace theold_namecolumn name.Returnspandas.DataFrame with the renamed column.columns_mismatch(col_1, col_2)DescriptionExtracts values that are present incol_1, but not incol_2.Parameterscol_1: pandas.SeriesThe Series you want to subtract values from.col_2: pandas.SeriesThe Series which is subtracted fromcol_1.Note: The word "subtract" is used not in arithmetical sense, but in a set difference sense.ReturnsSet with values whichcol_1contains andcol_2does not contain.df_difference(df_1, df_2)DescriptionExtracts rows that are present indf_1, but not indf_2.Note:df_1anddf_2can have different column names, but number of columns should match.Parametersdf_1: pandas.DataFrameThe DataFrame you want to subtract values from.df_2: pandas.DataFrameThe DataFrame which is subtracted fromdf_1.Note: The word "subtract" is used not in arithmetical sense, but in a set difference sense.Returnspandas.DataFrame with rows whichdf_1contains anddf_2does not contain.verify_dates_integity(df, date_col)DescriptionChecks whether there are any missing dates between earliest and latest dates fromdf[date_col]Parametersdf: pandas.DataFrameThe DataFrame which after selecting values fromdate_colwill be verified for integritydate_col: strName ofdfcolumn that will be verified for integrityduplicate(df, how, n_times)DescriptionExtends the specified DataFrame by repeating its rows.Parametersdf: pandas.DataFrameThe DataFrame which rows you want to repeathow: strStrategy for repeating. Should be either 'whole' (then [1,2] -> [1,2,1,2]) or
'element_wise' (then [1,2] -> [1,1,2,2])n_times: intNumber of repetitions of each rowReturnsExtended pandas.DataFrame with repeated rowsgroupby_to_list(df, by_cols, col_to_list)DescriptionExtracts values ofcol_to_listcolumn that correspond to the same values inby_colscolumn(s) and put them to list.Parametersdf: pandas.DataFrameThe DataFrame which you want to useby_cols: list of strColumn names that will be used as keys indfcol_to_list: strColumn name which values will be put to listsReturnspandas.DataFrame with columns [by_cols,col_to_list] so that all the values incol_to_listcolumn are lists.chunkenize(data_to_split, num_chunks, df_indices, copy)DescriptionSplits thedata_to_splitinto list withnum_chunkschunks. Can be helpful when preparing
data for parallel processing.Parametersdata_to_split: pandas.DataFrame or listThe DataFrame which you want to split in chunksnum_chunks: intNumber of chunks that your data will be split indf_indices: list of str, optional (default = [])This can be used whendata_to_splitis pandas.DataFrame. These column will be used
as DataFrame index before splitting and will be reset afterwards.copy: bool, optional (default = True)Determines whether you want to perform splitting on a copy ofdata_to_split.ReturnsList ofnum_chunkschunks that have same type asdata_to_split.filter_df(df, col_name, l_bound, r_bound, inclusive)DescriptionFilters thedfDataFramecol_namecolumn so that it contains only records
that corresponds todf[col_name] values in the range betweenl_boundandr_bound.Parametersdf: pandas.DataFrameThe DataFrame which columncol_nameyou want to filtercol_name: strColumn name fromdfwhich values you want to filterdfonl_bound: same type as values ofdf[col_name]Left bound of the filtered values range. Can be omitted ifr_boundis specifiedr_bound: same type as values ofdf[col_name]Right bound of the filtered values range. Can be omitted ifl_boundis specifiedinclusive: bool, optional (default = True)Determines whether you want range to be inclusive (True) or exclusive (False)ReturnsFiltered pandas.DataFrameprepare_str_cols(df, make_uppercase)DescriptionStrips leading and trailing spaces in str columns ofdfand makes those values to either upper-case or lower-case.Parametersdf: pandas.DataFrameThe DataFrame you want to prepare str columns for.make_uppercase: boolDetermines whether you want str values to be upper-cased or lower-cased.Returnspandas.DataFrame where all strings are either upper-cased or lower-cased with all leading and trailing spaces removed.