-1

I have a dataframe which is currently looks like this,

dataframe 1

I need to create a dataframe that looks like this.

dataframe 2

I need to populate the columns of dataframe 2 from the values from dataframe 1 columns. Image shows the example. What should be the algorithm and process for this?

Here is the sample dataset

df_dict = 
{'hostname': {0: 'Comp890263', 1: 'Comp813682', 2: 'Comp213302', 3: 'Comp839013', 4: 'Comp966241'},
 
'days': {0: 90, 1: 90, 2: 90, 3: 90, 4: 90}, 

'status': {0: '1', 1: '1', 2: '1', 3: '1', 4: '1'},
 
'features': 

{0: '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0',

 1: '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0', 

 2: '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0', 

 3: '0,0,0,0,0,0,0,21,0,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,6,46,0,0,0,0,759,0,0,0,0', 

 4: '0,0,0,0,0,0,0,43,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,0,0,0,0,0,0,0,0,0,30,46,0,0,0,0,795,0,0,0,0'}}
PREENCE
  • 33
  • 5
  • 1
    Please include sample code to create your test DataFrames. We can't recreate dataframes from your images. – Allen Qin Jan 23 '20 at 03:36
  • @Allen Hi. I would but the dataset is loaded into the dataframe from postgres local database. I just used df = pd.read_sql(query,conn) to load the data. – PREENCE Jan 23 '20 at 04:28
  • You can do a df.head().to_dict() and paste the data here so people can reconstruct the DF to help you. – Allen Qin Jan 23 '20 at 04:40
  • @Allen Thanks. I have added a sample dataset in dictionary for convenience. – PREENCE Jan 23 '20 at 15:21

1 Answers1

0

There is a similar question here :Pandas column values to columns?. See if their solutions with .pivot_table or unstack work for you.

Poe Dator
  • 4,535
  • 2
  • 14
  • 35