pythondataframeduplicatesreplicate

Replicate/duplicate first value (column A) over all columns in entire row


Does anyone know, how to get from this:

A B C D E F G
Rate RS 1.0 1.0 1.0 1.0 1.0 1.0

to this:

A B C D E F G
Rate RS RS RS RS RS RS RS

Solution

  • Try using slice assignment:

    df[:] = df.iloc[0, 0]
    

    Or if you want to specify the Rate index:

    >>> df[:] = df.loc['Rate'].iloc[0]
    >>> df
           A   B   C   D   E   F   G
    Rate  RS  RS  RS  RS  RS  RS  RS
    >>>