Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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)
like image 773
ferrelwill Avatar asked Oct 12 '25 06:10

ferrelwill


1 Answers

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
like image 189
cs95 Avatar answered Oct 14 '25 20:10

cs95