简体   繁体   中英

How to turn dictionary into a dataframe with only a subset of columns using pandas?

I am trying to convert the following dictionary format into dataframe with no success. How can I do that using instance_score and feature_score in input as columns in a dataframe?

input

{'data': {'f_score': None,
  'instance_score': array([ 0.99999967, -0.37898901, -0.38409877, ...,  0.0470927 ,
         -0.07509494,  0.32273143]),
  'feature_score': array([1, 0, 0, ..., 0, 0, 0])},
 'meta': {'data_type': 'time-series',
  'detr_type': 'line',
  'name': 'ad'}}

code

pd.DataFrame.from_dict(input)

You can call pd.DataFrame , specifying a subset of the columns you want to keep:

pd.DataFrame(d['data'], columns=['instance_score', 'feature_score'])

   instance_score  feature_score
0        1.000000              1
1       -0.378989              0
2       -0.384099              0
3        0.047093              0
4       -0.075095              0
5        0.322731              0

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