pigeon/data_processing.py
def reshape_to_row(data, col_names, idx, cols, source_column, filler, vals):
    """
    Use repeated values from one column as new columns, reshape dataframe.
    :param data: dataframe
    :param col_names: Array, names of columns to be used
    :param idx: String, column name to be used as index
    :param cols: String, column name to be used to create new columns
    :param source_column: String, name of the column
    :param filler: String, to fill empty term in created columns
    :param vals: Array/String, columns from initial df used as new df values
    :return: dataframe
    """
    # rename columns
    if col_names:
        data.columns = col_names

    # clean NaNs
    data_frame = data.replace(r'^\s*$', np.nan, regex=True)
    data_frame = data_frame.replace('X', np.nan)

    data_frame[cols] = data_frame.loc[data_frame[idx].isna(), source_column]
    data_frame[cols] = data_frame[cols].fillna(filler)

    data_frame[cols] = data_frame[cols].apply(lambda x: x.strip())
    data_frame[idx] = data_frame[idx].ffill()
    data_frame[idx] = data_frame[idx].astype(pd.StringDtype())
    data_frame = data_frame.pivot_table(index=idx, columns=cols,
                                        values=vals)
    return data_frame

    Use repeated values from one column as new columns, reshape dataframe.
    :param data: dataframe
    :param col_names: Array, names of columns to be used
    :param idx: String, column name to be used as index
    :param cols: String, column name to be used to create new columns
    :param source_column: String, name of the column
    :param filler: String, to fill empty term in created columns
    :param vals: Array/String, columns from initial df used as new df values
    :return: dataframe
    
Use repeated values from one column as new columns, reshape dataframe.
Use repeated values from one column as new columns reshape dataframe .
def reshape_to_row(data, col_names, idx, cols, source_column, filler, vals):
    if col_names:
        data.columns = col_names
    data_frame = data.replace(r'^\s*$', np.nan, regex=True)
    data_frame = data_frame.replace('X', np.nan)
    data_frame[cols] = data_frame.loc[data_frame[idx].isna(), source_column]
    data_frame[cols] = data_frame[cols].fillna(filler)
    data_frame[cols] = data_frame[cols].apply(lambda x: x.strip())
    data_frame[idx] = data_frame[idx].ffill()
    data_frame[idx] = data_frame[idx].astype(pd.StringDtype())
    data_frame = data_frame.pivot_table(index=idx, columns=cols,
                                        values=vals)
    return data_frame
def reshape_to_row ( data , col_names , idx , cols , source_column , filler , vals ) : if col_names : data . columns = col_names data_frame = data . replace ( r'^\s*$' , np . nan , regex = True ) data_frame = data_frame . replace ( 'X' , np . nan ) data_frame [ cols ] = data_frame . loc [ data_frame [ idx ] . isna ( ) , source_column ] data_frame [ cols ] = data_frame [ cols ] . fillna ( filler ) data_frame [ cols ] = data_frame [ cols ] . apply ( lambda x : x . strip ( ) ) data_frame [ idx ] = data_frame [ idx ] . ffill ( ) data_frame [ idx ] = data_frame [ idx ] . astype ( pd . StringDtype ( ) ) data_frame = data_frame . pivot_table ( index = idx , columns = cols , values = vals ) return data_frame
Use repeated values from one column as new columns, reshape dataframe.
Use repeated values from one column as new columns reshape dataframe .
"""
    Use repeated values from one column as new columns, reshape dataframe.
    :param data: dataframe
    :param col_names: Array, names of columns to be used
    :param idx: String, column name to be used as index
    :param cols: String, column name to be used to create new columns
    :param source_column: String, name of the column
    :param filler: String, to fill empty term in created columns
    :param vals: Array/String, columns from initial df used as new df values
    :return: dataframe
    """ # rename columns # clean NaNs
None
data
None
col_names
Array, names of columns to be used
Array names of columns to be used
idx
String, column name to be used as index
String column name to be used as index
cols
String, column name to be used to create new columns
String column name to be used to create new columns
source_column
String, name of the column
String name of the column
filler
String, to fill empty term in created columns
String to fill empty term in created columns
vals
Array/String, columns from initial df used as new df values
Array / String columns from initial df used as new df values