Interaction with PandasΒΆ

In this example we are going to explore interaction with Pandas data analysis tool.

[1]:
from __future__ import print_function
import openturns as ot
import pandas as pd
[2]:
# create a sample from a 3-d gaussian distribution
sample = ot.Normal(3).getSample(10)
[3]:
# Create a DataFrame from a Sample
df = pd.DataFrame.from_records(sample, columns=sample.getDescription())
df.describe()
[3]:
X0 X1 X2
count 10.000000 10.000000 10.000000
mean 0.201254 -0.341580 -0.143151
std 1.122471 1.126257 0.678845
min -2.290062 -2.181385 -1.311781
25% -0.288951 -1.209149 -0.695591
50% 0.459701 -0.298012 0.060783
75% 0.746917 0.351669 0.343263
max 1.782359 1.437249 0.810668
[4]:
# Create a Sample from a DataFrame
sample2 = ot.Sample(df.values)
sample2.setDescription(df.columns)
sample2
[4]:
X0X1X2
00.6082016512187646-1.2661731022166567-0.43826561996041397
11.2054782008285756-2.18138523461651430.3500420865302907
2-0.35500704918563971.4372493101409030.8106679824694837
30.79315601145977-0.47052559863257040.26101793529769673
4-2.2900619818700854-1.2828852904549808-1.311781115463341
5-0.090783826580494890.9957932259165571-0.13945281896393122
6-0.56020560003784750.44548969729905190.32292503034661274
70.44578529818450985-1.0380765948630941-0.8567122780208447
80.4736169171884015-0.125497745412560040.35141776801611424
91.78235863993871680.070207359297043-0.7813664602347197