pythondataframe

How to Change Feet and Inches Object Type Data Frame to Inches: Python


I have data frames containing Height data like this

enter image description here

How to change into inches with dtype:float ? thankyou


Solution

  • Try:

    df["Heigth_inches"] = (df.Height.str.split("'").str[0].astype(int) * 12) + (
        df.Height.str.split("'").str[1].astype(int)
    )
    print(df)
    

    Prints:

      Height  Heigth_inches
    0    5'7             67
    1    6'2             74
    2    5'9             69
    3   5'11             71
    4   5'10             70
    

    EDIT: Changed the computation, thanks @Serge