Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23218

Raw string producting syntax error : unterminated string literal

$
0
0
def topcarmodel(df):    df = df[df['units sold_per annum'] >= 1000]    df['price'] = df['price'].str.replace(r'[^0-9.]', '')    df['price'] = pd.to_numeric(df['price'])    df['commission'] = df['price'] * df['units sold_per annum'] * (df['dealer commission'] / 100)    max_commission_idx = df.groupby('car company-manufacturer')['commission'].idxmax()    top_models_df = df.loc[max_commission_idx]    return top_models_df.sort_values(by='car company-manufacturer')

in above code at line

df['price'] = df['price'].str.replace(r'[^0-9.]', '')

I am getting an error

Syntax error : unterminated string literal

I have tried the following

df['price'] = df['price'].str.replace(r'[^0-9.]', '', regex=True)

still same error is being produced.

A bit of background, I have a dataframe with various columns like car company , carmodel , units sold per annum , prce and dealer_commision. And I'm trying to clean this data frame using the above code snippet.

df example

car company,car_model,price, units_sold_per_annum, dealer_commissionBMW, bmw m90,899861g1,3222,3.7TESLA, tesla_m43,nr96388eQ,8268,2.4FIAT, fiat m149, TC66248ng, 2862,2.5FIAT, fiat m142, TC63248ng, 545,2.5TESLA, tesla_m44,ib97830k1,6581,2.8TESLA, tesla_m88,oh400863F, 9522,1.9HONDA, honda_m63,pw58054jK,4723,0.7ISUZU, isuzu_m7, AX82846sm,6100,2.6ISUZU, isuzu_m9, AX81896sm, 999,2.6

Viewing all articles
Browse latest Browse all 23218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>