I have a list of dictionaries with values that are returned as numpy arrays (and which are often empty).
data=[{'width': array([])},
{'width': array([])},
{'width': array([])},
{'width': array([])},
{'width': array([])},
{'width': array([ 0.64848222])},
{'width': array([ 0.62241745])},
{'width': array([ 0.76892571])},
{'width': array([ 0.69913647])},
{'width': array([ 0.7506934])},
{'width': array([ 0.69087949])},
{'width': array([ 0.65302866])},
{'width': array([ 0.67267989])},
{'width': array([ 0.63862089])}]
I would like to create a DataFame were the values are floats and not of numpy array dtype. Also I'd like to the empty arrays to be converted to NaN values.
I have tried using df=pd.DataFrame(data, dtype=float) which returns a DataFame with values as np.arrays as such:
width
0 []
1 []
2 []
3 []
4 []
5 [0.648482224582]
6 [0.622417447245]
7 [0.768925710479]
8 [0.699136467373]
9 [0.75069339816]
10 [0.690879488242]
11 [0.653028655088]
12 [0.672679885077]
13 [0.638620890633]
I've also tried recasting the df's values after creating it using df.values.astype(float) but get the following error:
ValueError: setting an array element with a sequence.
The final output I am trying to get for the DataFame looks like:
width
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
5 0.648482224582
6 0.622417447245
7 0.768925710479
8 0.699136467373
9 0.75069339816
10 0.690879488242
11 0.653028655088
12 0.672679885077
13 0.638620890633