[Python] Create column from another dataframe, using existing columns

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have a pandas DataFrame with columns "Quantity" and "Unit", e.g.:

    Quantity Unit
    0 Current A
    1 Current mA
    2 Voltage V
    3 Length m
    4 Length km


    and I have a pandas DataFrame with ratios of units, e.g.:

    Current Voltage Length
    A 1 NaN NaN
    mA 1000 NaN NaN
    V NaN 1 NaN
    m NaN NaN 1000
    km NaN NaN 1


    Is it possible to create in first dataframe column with values of ratios?:

    Quantity Unit Ratio
    0 Current A 1
    1 Current mA 1000
    2 Voltage V 1
    3 Length m 1
    4 Length km 1000


    I have tried to get every value by iterrows, but I have really big dataframe and it's not working correctly in case of time. Maybe there is another, more expedient way to solve my issue, but I have to work with dataframes of ratios.

    Continue reading...

Compartilhe esta Página