1

I have an array of tuples like:

myArr=Ttest_indResult(statistic=array([ -5.27693006,   0.,   0.,   0.15105006,]),
 pvalue=array([  2.31902785e-06,   1.00000000e+00,   1.00000000e+00,
     8.80460569e-01,)]))

I want to add the values myArr[1][0],myArr[1][1],myArr[1][2] and myArr[1][3] to a new data frame:

df_tup = pd.DataFrame()
df_tup['t']=df_tup['t'].apply(lambda x: myArr[1][x]...not sure)

not sure how to iterate through the array while adding a value to the column t.

magicsword
  • 1,179
  • 3
  • 16
  • 26

1 Answers1

1

myArr is not exactly a tuple but rather a namedtuple (see scipy.stats source code), which allow to access its fields like arguments, and the names of these fields.

As in your case it encapsulates two numpy.array (see scipy.stats.ttest_ind doc) you can use it directly as values for your new columns.

pd.DataFrame(columns=myArr._fields, data=np.array(myArr).T)
Out[]:
   statistic    pvalue
0   -5.27693  0.000002
1    0.00000  1.000000
2    0.00000  1.000000
3    0.15105  0.880461

inspired from this answer

FabienP
  • 3,018
  • 1
  • 20
  • 25