Search code examples
pythonpython-3.xpandasdataframedata-cleaning

Pandas DataFrame Issue. Don't know how to clean and manage a sort of block matrix


here is my first question: I have a pandas DataFrame that looks like the following:

Pandas Dataframe

The DataFrame shown in the picture is simplified (its original shape is [1195674 x 11]) but it doesn't matter.

I am trying to set the left hand side (columns A, B, C, D) as index and the right hand side (columns E, F, G) as corresponding values (look at the colors).

Do you have any hint?

P.S. another way could be to replicate the left hand side (rows) in order to have something like the following (the red rows should be cancelled out):

Second Solution

Can you propose any other way to accomplish this task?

Many thanks in advance!

Franco


Solution

  • Let's try ffill, which will fill forward values for NaN:

    df[['A','B','C','D']] = df[['A','B','C','D']].ffill()