0

I am finding the t confidence interval across rows of my dataframe:

df = pd.DataFrame({'nums_1': [1, 2, 3], 'nums_2': [1, 1, 5], 'nums_3' : [8,7,9]})    


df['CI']=df.apply(lambda row: stats.t.interval(0.95, len(df)-1, 
loc=np.mean(row), scale=stats.sem(row)), axis=1)

How can I get the confidence intervals given to me by scipy stats t interval to be rounded to two decimal places?

Niam45
  • 552
  • 2
  • 16

1 Answers1

0

.apply() a lambda function that uses np.round() to two decimal places.

df["CI"] = df["CI"].apply(lambda x: np.round(x,2))
df

Output:

enter image description here

butterflyknife
  • 1,438
  • 8
  • 17