[Python] How do I transfer data from pandas Dataframe to a Dataframe variable of a different...

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    So I have a Dataframe of car data which has a price column. [​IMG]

    So I want to transfer the data from the price column a variable which is a Dataframe which has the same data as the original column, but I don't want to modify the original Dataframe. So far I have tried this

    # Group columns of the car sales DataFrame by the Make column and find the average
    price_list = car_sales["Price"].str.replace("$", "").replace(",", "")
    price_data = pd.to_numeric(price_list, errors="coerce")
    car_sales.groupby("Make")[price_data].mean()


    The issue is that while I am getting the cleaned data contained in price_list is not in the correct format to be passed in as an argument to the to_numeric function. The to_numeric function keeps returning NaN where the price data should be.

    [​IMG]

    Continue reading...

Compartilhe esta Página