0
  1. I Have a table like below: enter image description here

  2. I converted the table as I needed like this: enter image description here

  3. But I want to categorize the values with the column names like this (example of result needed): enter image description here

Here's my code:

inv_power = inv_power.set_axis(['Timestamp', 'Time', 'INV1','INV2','INV3','INV4','INV5','INV6','INV7','INV8','INV9','INV10', 'INV11','INV12','INV13','INV14','INV15','INV16','INV17','INV18','INV19','INV20'], axis=1) 

inv_power = inv_power.replace('', np.nan).set_index('Timestamp').stack().reset_index(name='AC_Power').drop('level_1', 1)
Chio
  • 43
  • 4
  • 2
    Please post a small reproducible sample of the data so that we can try to help you out. Images do not help as much as the data will. – Aman Nov 06 '21 at 13:57
  • okay, edited with some lines of code – Chio Nov 06 '21 at 14:00
  • 1
    Please provide a sample of your data such that I can copy it and run it on my own end. A subset of the main dataframe would be enough. What you've posted above is not enough, since `name 'inv_power' is not defined`. [Edit your answer with something like this](https://stackoverflow.com/a/47451083/4112751). – Aman Nov 06 '21 at 14:02

1 Answers1

0

This should work:

inv_power['Slot No.'] = pd.np.tile(inverter, len(inv_power) // len(inverter)).tolist() + inverter[:len(inv_power)%len(inverter)]
RiveN
  • 2,595
  • 11
  • 13
  • 26
Chio
  • 43
  • 4