def to_kilowatts(data, derate, power_fac):
    """Unit conversion and electricity usage/heat rate adjustments.

    Converts heat flow from btu/hr to kW and electricity from W to kW.
    Scales heat flow and electricity consumption values.

    Parameters
    ----------
    data : pd.DataFrame
        Heat pump operational data.
    derate : float
        Scales heat flow values.
    power_fac : float
        Scales electricity usage.

    Returns
    -------
    pd.DataFrame
        Dataframe with unit conversion and necessary scaling applied to
        electricity usage and heatflow. Additional columns are
        as follows:

        =======  =======================================================
        q        heat flow in kW with scaling (as `float`)
        kw_used  electricity usage in kW with scaling (as `float`)
        =======  =======================================================

    """

    # btu/hr to kw
    data['q'] = derate*(0.29307107*data['heat_flow_rate'])/1000
    data['q'].fillna(0.0, inplace=True)
    # w to kw
    data['kw_used'] = power_fac * data['heatpump_power']/1000
    return data