简体   繁体   中英

Python - Pandas Dataframe Table/Column Structure

  1. I Have a table like below: 在此处输入图片说明

  2. I converted the table as I needed like this: 在此处输入图片说明

  3. But I want to categorize the values with the column names like this (example of result needed): 在此处输入图片说明

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)

inv_power['Slot No.']= pd.np.tile(inverter, len(inv_power) // len(inverter)).tolist() + inverter[:len(inv_power)%len(inverter)]

try this... this works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM