notebooks/common.py
def remove_footnotes(t: pd.DataFrame) -> pd.DataFrame:
    """Remove Wikipedia footnote references from the Brand column"""
    
    BRAND = ['Brand', 'Firm']
    
    for brand in BRAND:
        if brand not in t.columns.get_level_values(0):
            continue
        col = t.columns[t.columns.get_level_values(0) == brand]
        assert(len(col) == 1)
        t.loc[:, col] = (
            t.loc[:, col] # returns a single column DataFrame
            .pipe(lambda x: x[x.columns[0]]) # make as Series
            .str.replace('\[.*\]$', '', regex=True) # remove footnotes
            .str.strip() # remove any leading/trailing whitespaces
        )
    return t
Remove Wikipedia footnote references from the Brand column
Remove Wikipedia footnote references from the Brand column
Remove Wikipedia footnote references from the Brand column
def remove_footnotes(t: pd.DataFrame) -> pd.DataFrame:
    BRAND = ['Brand', 'Firm']
    for brand in BRAND:
        if brand not in t.columns.get_level_values(0):
            continue
        col = t.columns[t.columns.get_level_values(0) == brand]
        assert(len(col) == 1)
        t.loc[:, col] = (
            t.loc[:, col] 
            .pipe(lambda x: x[x.columns[0]]) 
            .str.replace('\[.*\]$', '', regex=True) 
            .str.strip() 
        )
    return t
def remove_footnotes ( t : pd . DataFrame ) -> pd . DataFrame : BRAND = [ 'Brand' , 'Firm' ] for brand in BRAND : if brand not in t . columns . get_level_values ( 0 ) : continue col = t . columns [ t . columns . get_level_values ( 0 ) == brand ] assert ( len ( col ) == 1 ) t . loc [ : , col ] = ( t . loc [ : , col ] . pipe ( lambda x : x [ x . columns [ 0 ] ] ) . str . replace ( '\[.*\]$' , '' , regex = True ) . str . strip ( ) ) return t
Remove Wikipedia footnote references from the Brand column
Remove Wikipedia footnote references from the Brand column
"""Remove Wikipedia footnote references from the Brand column""" # returns a single column DataFrame # make as Series # remove footnotes # remove any leading/trailing whitespaces
t
pd.DataFrame