Example mediation analysis for the host and microbiome features.

Mediation is modelled according to the statsmodels.stats.mediation package: Basic mediation analysis with regression model according to [1].

The outcome model: FeatureValue_1 ~ Drug + FeatureValue_2

is tested against mediator model: FeatureValue_2 ~ Drug,

where FeatureValue1 and FeatureValue2 are associated with the Drug treatment.
Mediation analysis is performed in both directions (FeatureValue1 is tested as mediator and FeatureValue2 is tested as mediator).

The script crreates mediation results dataframe and saves it to file.

[1] Imai, Keele, Tingley (2010). A general approach to causal mediation analysis. Psychological Methods 15:4, 309-334. http://imai.princeton.edu/research/files/BaronKenny.pdf

Required files in the input_data folder:

  • Supplementary_Tables_1_to_4_2019-09-13434.xlsx

Supplementary Tables 1 to 4 include information on the cohort characteristics and drug intake with source metadata. Source metadata for the MetaCardis cohort includes disease group, gender, age, study center, body mass index (BMI, kg/m2), alternative healthy eating index (aHEI), diet diversity score (DDS), and dietary approaches to stop hypertension (DASH), physical activity and manual work levels, and smoking status. Source data includes information on the drug intake, drug combinations, dosage and antibiotic use analyzed in the MetaCardis cohort.

  • Supplementary_Table_8_2019-09-13434.xlsx

Supplementary Table 8: Features of microbiome, host and metabolome impacted by different drug combinations. Analysis of the effect of drug combinations, assessed for impact on host and microbiome falling within different measurement categories in each patient group.

  • example_feature_table.csv

File with source data on host and microbiome feature values per sample.

In [1]:
# load necessary libraries
import pandas as pd
import numpy as np
from scipy import stats
import statsmodels.api as sm
from statsmodels.stats.mediation import Mediation
from IPython.display import display
In [2]:
# prepare file names to download: phenotype, drug and feature information
fileFolder = './input_data/'

featureFile = 'example_feature_table.csv'
hubfileDrugDosage = 'Supplementary_Tables_1_to_4_2019-09-13434.xlsx'
sheetDrug = 'ST 2b'
# supplementary table 8 to filter features affected by drug combinations
fileName = 'Supplementary_Table_8_2019-09-13434.xlsx'

# read file names with features
features_df = pd.read_csv(fileFolder + featureFile, sep=',', index_col=0)

featuresDrug = pd.read_excel(fileFolder + hubfileDrugDosage, 
                           sheet_name = sheetDrug)
# read drug combination features files
sheetName = 'Data'
drugCombinationEffect = pd.read_excel(fileFolder + fileName,
                           sheet_name = sheetName)
In [3]:
# Read patient group information from Supplementary Table 1
hubfilePhenotype = 'Supplementary_Tables_1_to_4_2019-09-13434.xlsx'
sheetName = 'ST 1b'
indication_df =  pd.read_excel(fileFolder + hubfilePhenotype,
                               sheet_name = sheetName)
In [4]:
# create dataframe with sample - group
featuresGroup = indication_df[['SampleID', 'PatientGroup']]
featuresGroup = featuresGroup.drop_duplicates()
featuresGroup = featuresGroup.set_index('SampleID', drop=True)
##################################################################
# keep only samples for which features are avaiable
common_samples = list(set(featuresGroup.index).intersection(features_df.index))
featuresGroup = featuresGroup.loc[common_samples,:]
In [5]:
#######################################
# select drug combinations and condition for which to perform analysis
drug_pairs = [['STATINE_C', 'METFORMIN_C'],
              ['STATINE_C', 'ASA_C'],
              ['STATINE_C', 'CA2_CBL_C']]

drug_pairs_names = [['Statin', 'Metformin'],
                    ['Statin', 'Aspirin'],
                    ['Statin', 'Calcium antagonist']]

cursampleset = '3' #T2D group

# perform mediation analysis for each drug pair
feat_names1 = []
feat_names2 = []
featcorr_DrugFeat = []
featcorrP_DrugFeat = []
featcorr_1_2 = []
featcorrP_1_2 = []
feat_medres = [] 
feat_drugcombo = []

for drug_i in range(len(drug_pairs)):
    drug_name1 = drug_pairs[drug_i][0]
    drug_name2 = drug_pairs[drug_i][1]
    
    # extract dataframe for current drug 
    drug_df = featuresDrug[[item for item in featuresDrug.columns 
                              if (drug_name1 in item) |
                                 (drug_name2 in item)]].copy()
    drug_df.index = featuresDrug['SampleID']
    # column Drug contains combination
    drug_df['Drug'] = drug_df.iloc[:,0] * drug_df.iloc[:,1]
    # overlap with phenotype 
    drug_df = drug_df.loc[featuresGroup.index]
    drug_df['Group'] = featuresGroup.loc[drug_df.index,'PatientGroup']
    
    #############################
    # get feature names that are changing in this combination
    associated_features = drugCombinationEffect[(drugCombinationEffect['Effector'].str.find(drug_pairs_names[drug_i][0])>=0) &
                                                (drugCombinationEffect['Effector'].str.find(drug_pairs_names[drug_i][1])>=0) &
                                                (drugCombinationEffect['Sample set'].str.find(cursampleset)>=0)].copy()
    selected_features = list(set(associated_features['Feature display name']).intersection(features_df.columns))
    #############################
    
    print('Running mediation analysis for combination ', drug_name1, ' and ', drug_name2, ' in ', cursampleset)
    
    
    for i in range(len(selected_features)):
        feat1name = selected_features[i]
        for j in range(i+1, len(selected_features)):
            
            feat2name = selected_features[j]
            print('Performing mediation analysis for ', feat1name, ' and ', feat2name)
            # add features to drug df
            drugmediation_df = pd.concat([drug_df, features_df.loc[:,[feat1name,feat2name]]], axis=1)
            # select only patients from one group
            testdata = drugmediation_df[drugmediation_df['Group']==cursampleset].copy()
            # reaplce nans with 0
            testdata = testdata.fillna(0)
            # doublecheck that feature values are numeric
            testdata[feat1name] = pd.to_numeric(testdata[feat1name])
            testdata[feat2name] = pd.to_numeric(testdata[feat2name])
            
            #rename columns to generic for easier formula definition for mediation analysis
            testdata.columns = [item.replace(feat1name, 'FeatureValue_1') for item in testdata.columns]
            testdata.columns = [item.replace(feat2name, 'FeatureValue_2') for item in testdata.columns]
            
            # change drug from boolean to 0 and 1
            testdata['Drug'] = [1 if testdata['Drug'].iloc[i]==True else 0 for i in range(len(testdata))]
            # model feature 1 as mediator
            outcome_model = sm.OLS.from_formula("FeatureValue_1 ~ Drug + FeatureValue_2",
                                                data = testdata)
            mediator_model = sm.OLS.from_formula("FeatureValue_2 ~ Drug",
                                                  data = testdata)
    
            med = Mediation(outcome_model, mediator_model, "Drug", "FeatureValue_2")
    
            med_result = med.fit(n_rep = 100)
            res = med_result.summary()
            # save results
            feat_names1.append(feat1name)
            feat_names2.append(feat2name)
            feat_medres.append(res) 
            #model feature 2 as mediator
            outcome_model = sm.OLS.from_formula("FeatureValue_2 ~ Drug + FeatureValue_1",
                                        data = testdata)
            mediator_model = sm.OLS.from_formula("FeatureValue_1 ~ Drug",
                                                  data = testdata)
    
            med = Mediation(outcome_model, mediator_model, "Drug", "FeatureValue_1")
    
            med_result = med.fit(n_rep = 100)
            res = med_result.summary()
            # save results
            feat_names1.append(feat2name)
            feat_names2.append(feat1name)
            feat_medres.append(res) 
    
            # calculate correlations
            res = stats.spearmanr(testdata['Drug'], testdata['FeatureValue_1'])
            featcorr_DrugFeat.append(res[0])
            featcorrP_DrugFeat.append(res[1])
    
            res = stats.spearmanr(testdata['Drug'], testdata['FeatureValue_2'])
            featcorr_DrugFeat.append(res[0])
            featcorrP_DrugFeat.append(res[1])
    
            res = stats.spearmanr(testdata['FeatureValue_1'], testdata['FeatureValue_2'])
            featcorr_1_2.append(res[0])
            featcorrP_1_2.append(res[1])
    
            res = stats.spearmanr(testdata['FeatureValue_2'], testdata['FeatureValue_1'])
            featcorr_1_2.append(res[0])
            featcorrP_1_2.append(res[1])
            
            feat_drugcombo.append('Combination: ' + drug_name1 + ', ' + drug_name2)
            feat_drugcombo.append('Combination: ' + drug_name1 + ', ' + drug_name2)

# compile dataframe with mediation results
medres_df = []
for i in range(len(feat_medres)):
    df = feat_medres[i].copy()
    df = pd.melt(df.assign(index=df.index), id_vars=['index'])
    df = pd.DataFrame(np.reshape(df['value'].values,(1,np.shape(df)[0])),
                  columns=df['index']+'_'+df['variable'])
    if i==0:
        medres_df = df
    else:
        medres_df = pd.concat([medres_df, df])

medres_df['Feature1'] = feat_names1
medres_df['Feature2_med'] = feat_names2
        
medres_df['FeatureDrugCorr'] = featcorr_DrugFeat
medres_df['FeatureDrugCorrP'] = featcorrP_DrugFeat
medres_df['FeatureFeatureCorr'] = featcorr_1_2
medres_df['FeatureFeatureCorrP'] = featcorrP_1_2
medres_df['Effector'] = feat_drugcombo
medres_df['Sample set'] = cursampleset
Running mediation analysis for combination  STATINE_C  and  METFORMIN_C  in  3
Performing mediation analysis for  methanogenesis (trimethylamine degradation) (MC0025)  and  Fat mass in %
Performing mediation analysis for  methanogenesis (trimethylamine degradation) (MC0025)  and  IDL Phospholipids mg/dL
Performing mediation analysis for  methanogenesis (trimethylamine degradation) (MC0025)  and  Xylene degradation, xylene => methylbenzoate (M00537)
Performing mediation analysis for  methanogenesis (trimethylamine degradation) (MC0025)  and  Toluene degradation, toluene => benzoate (M00538)
Performing mediation analysis for  Fat mass in %  and  IDL Phospholipids mg/dL
Performing mediation analysis for  Fat mass in %  and  Xylene degradation, xylene => methylbenzoate (M00537)
Performing mediation analysis for  Fat mass in %  and  Toluene degradation, toluene => benzoate (M00538)
Performing mediation analysis for  IDL Phospholipids mg/dL  and  Xylene degradation, xylene => methylbenzoate (M00537)
Performing mediation analysis for  IDL Phospholipids mg/dL  and  Toluene degradation, toluene => benzoate (M00538)
Performing mediation analysis for  Xylene degradation, xylene => methylbenzoate (M00537)  and  Toluene degradation, toluene => benzoate (M00538)
Running mediation analysis for combination  STATINE_C  and  ASA_C  in  3
Performing mediation analysis for  Fat mass in %  and  glutamate degradation III (MF0032)
Performing mediation analysis for  Fat mass in %  and  IDL Apo-B mg/dL
Performing mediation analysis for  Fat mass in %  and  IDL Phospholipids mg/dL
Performing mediation analysis for  Fat mass in %  and  observed species richness
Performing mediation analysis for  Fat mass in %  and  unclassified Oscillibacter (CAG00961)
Performing mediation analysis for  Fat mass in %  and  VLDL-3 Cholesterol mg/dL
Performing mediation analysis for  glutamate degradation III (MF0032)  and  IDL Apo-B mg/dL
Performing mediation analysis for  glutamate degradation III (MF0032)  and  IDL Phospholipids mg/dL
Performing mediation analysis for  glutamate degradation III (MF0032)  and  observed species richness
Performing mediation analysis for  glutamate degradation III (MF0032)  and  unclassified Oscillibacter (CAG00961)
Performing mediation analysis for  glutamate degradation III (MF0032)  and  VLDL-3 Cholesterol mg/dL
Performing mediation analysis for  IDL Apo-B mg/dL  and  IDL Phospholipids mg/dL
Performing mediation analysis for  IDL Apo-B mg/dL  and  observed species richness
Performing mediation analysis for  IDL Apo-B mg/dL  and  unclassified Oscillibacter (CAG00961)
Performing mediation analysis for  IDL Apo-B mg/dL  and  VLDL-3 Cholesterol mg/dL
Performing mediation analysis for  IDL Phospholipids mg/dL  and  observed species richness
Performing mediation analysis for  IDL Phospholipids mg/dL  and  unclassified Oscillibacter (CAG00961)
Performing mediation analysis for  IDL Phospholipids mg/dL  and  VLDL-3 Cholesterol mg/dL
Performing mediation analysis for  observed species richness  and  unclassified Oscillibacter (CAG00961)
Performing mediation analysis for  observed species richness  and  VLDL-3 Cholesterol mg/dL
Performing mediation analysis for  unclassified Oscillibacter (CAG00961)  and  VLDL-3 Cholesterol mg/dL
Running mediation analysis for combination  STATINE_C  and  CA2_CBL_C  in  3
Performing mediation analysis for  VLDL Cholesterol mg/dL  and  VLDL-3 Cholesterol mg/dL
Performing mediation analysis for  VLDL Cholesterol mg/dL  and  Alistipes sp. (motu_linkage_group_621)
Performing mediation analysis for  VLDL-3 Cholesterol mg/dL  and  Alistipes sp. (motu_linkage_group_621)
In [6]:
###############################
# select a subset of columns to print to file
medres_df = medres_df[['Effector',                  # drug combination pair
                       'Sample set',                # patient group
                       'Feature1', 'Feature2_med',  # Feature (1) and mediator (2)
                       'ACME (average)_Estimate',   # Average estimate of mediated effect
                       'ADE (average)_Estimate',    # Average estimate of direct drug effect
                       'Total effect_Estimate',     # Estimate of total effect
                       'ACME (average)_P-value',    # P-value of mediated effect
                       'ADE (average)_P-value',     # P-value of direct drug effect
                       'Total effect_P-value',      # P-value of total effect
                       'FeatureDrugCorr', 'FeatureDrugCorrP',   # Pearson corr and p-value between drug and Feature 1
                       'FeatureFeatureCorr', 'FeatureFeatureCorrP']] #Pearson corr and p-value between Feature 1 and Feature 2
In [7]:
# display mediation analysis results
display(medres_df[medres_df['ACME (average)_P-value']<=0.1])
Effector Sample set Feature1 Feature2_med ACME (average)_Estimate ADE (average)_Estimate Total effect_Estimate ACME (average)_P-value ADE (average)_P-value Total effect_P-value FeatureDrugCorr FeatureDrugCorrP FeatureFeatureCorr FeatureFeatureCorrP
0 Combination: STATINE_C, METFORMIN_C 3 methanogenesis (trimethylamine degradation) (M... IDL Phospholipids mg/dL 4.067087e-01 2.657963e+00 3.064672e+00 0.06 0.12 0.04 0.097740 0.027763 -0.103989 1.917792e-02
0 Combination: STATINE_C, METFORMIN_C 3 IDL Phospholipids mg/dL methanogenesis (trimethylamine degradation) (M... -8.581148e-02 -9.923703e-01 -1.078182e+00 0.08 0.00 0.00 -0.134253 0.002452 -0.103989 1.917792e-02
0 Combination: STATINE_C, METFORMIN_C 3 methanogenesis (trimethylamine degradation) (M... Xylene degradation, xylene => methylbenzoate (... 2.874355e-01 2.734773e+00 3.022209e+00 0.10 0.06 0.06 0.097740 0.027763 0.411764 3.614441e-22
0 Combination: STATINE_C, METFORMIN_C 3 Xylene degradation, xylene => methylbenzoate (... methanogenesis (trimethylamine degradation) (M... 7.861214e-01 7.363589e+00 8.149710e+00 0.06 0.04 0.02 0.135474 0.002236 0.411764 3.614441e-22
0 Combination: STATINE_C, METFORMIN_C 3 methanogenesis (trimethylamine degradation) (M... Toluene degradation, toluene => benzoate (M00538) 2.713634e-01 2.594030e+00 2.865394e+00 0.04 0.02 0.00 0.097740 0.027763 0.411764 3.614441e-22
0 Combination: STATINE_C, METFORMIN_C 3 Toluene degradation, toluene => benzoate (M00538) methanogenesis (trimethylamine degradation) (M... 8.157255e-01 6.579971e+00 7.395697e+00 0.06 0.00 0.00 0.135474 0.002236 0.411764 3.614441e-22
0 Combination: STATINE_C, METFORMIN_C 3 IDL Phospholipids mg/dL Xylene degradation, xylene => methylbenzoate (... -9.192514e-02 -9.658385e-01 -1.057764e+00 0.10 0.00 0.00 -0.134253 0.002452 -0.123063 5.525573e-03
0 Combination: STATINE_C, METFORMIN_C 3 Xylene degradation, xylene => methylbenzoate (... IDL Phospholipids mg/dL 1.046951e+00 6.909280e+00 7.956232e+00 0.02 0.06 0.04 0.135474 0.002236 -0.123063 5.525573e-03
0 Combination: STATINE_C, METFORMIN_C 3 Toluene degradation, toluene => benzoate (M00538) IDL Phospholipids mg/dL 1.062685e+00 6.703223e+00 7.765908e+00 0.02 0.04 0.00 0.135474 0.002236 -0.123063 5.525573e-03
0 Combination: STATINE_C, METFORMIN_C 3 Xylene degradation, xylene => methylbenzoate (... Toluene degradation, toluene => benzoate (M00538) 7.865923e+00 -3.021668e-15 7.865923e+00 0.02 0.02 0.02 0.135474 0.002236 1.000000 0.000000e+00
0 Combination: STATINE_C, ASA_C 3 Fat mass in % IDL Apo-B mg/dL -4.739530e-01 -5.091902e+00 -5.565855e+00 0.06 0.00 0.00 -0.170021 0.000120 0.164283 2.029994e-04
0 Combination: STATINE_C, ASA_C 3 IDL Apo-B mg/dL Fat mass in % -6.142944e-02 -8.119422e-01 -8.733717e-01 0.00 0.00 0.00 -0.159421 0.000314 0.164283 2.029994e-04
0 Combination: STATINE_C, ASA_C 3 Fat mass in % IDL Phospholipids mg/dL -4.086770e-01 -5.257336e+00 -5.666013e+00 0.08 0.02 0.00 -0.170021 0.000120 0.146338 9.506884e-04
0 Combination: STATINE_C, ASA_C 3 Fat mass in % unclassified Oscillibacter (CAG00961) -4.394313e-01 -5.074914e+00 -5.514345e+00 0.02 0.00 0.00 -0.170021 0.000120 -0.132621 2.771203e-03
0 Combination: STATINE_C, ASA_C 3 unclassified Oscillibacter (CAG00961) Fat mass in % 7.125284e-01 6.975826e+00 7.688354e+00 0.04 0.00 0.00 0.155978 0.000423 -0.132621 2.771203e-03
0 Combination: STATINE_C, ASA_C 3 glutamate degradation III (MF0032) IDL Phospholipids mg/dL 5.679054e+00 5.491392e+01 6.059298e+01 0.04 0.00 0.00 0.142198 0.001326 -0.102674 2.076148e-02
0 Combination: STATINE_C, ASA_C 3 IDL Phospholipids mg/dL glutamate degradation III (MF0032) -1.850709e-01 -2.052533e+00 -2.237604e+00 0.08 0.00 0.00 -0.167196 0.000156 -0.102674 2.076148e-02
0 Combination: STATINE_C, ASA_C 3 glutamate degradation III (MF0032) observed species richness 9.858520e+00 5.154796e+01 6.140647e+01 0.06 0.00 0.00 0.142198 0.001326 0.505340 3.229817e-34
0 Combination: STATINE_C, ASA_C 3 observed species richness glutamate degradation III (MF0032) 5.632975e+00 8.242027e+00 1.387500e+01 0.00 0.16 0.02 0.105616 0.017365 0.505340 3.229817e-34
0 Combination: STATINE_C, ASA_C 3 glutamate degradation III (MF0032) unclassified Oscillibacter (CAG00961) 7.425056e+00 5.513345e+01 6.255851e+01 0.00 0.00 0.00 0.142198 0.001326 0.357974 8.968605e-17
0 Combination: STATINE_C, ASA_C 3 unclassified Oscillibacter (CAG00961) glutamate degradation III (MF0032) 1.528181e+00 6.156024e+00 7.684204e+00 0.00 0.02 0.02 0.155978 0.000423 0.357974 8.968605e-17
0 Combination: STATINE_C, ASA_C 3 glutamate degradation III (MF0032) VLDL-3 Cholesterol mg/dL 3.177767e+00 5.874200e+01 6.191976e+01 0.10 0.00 0.00 0.142198 0.001326 -0.058294 1.900426e-01
0 Combination: STATINE_C, ASA_C 3 IDL Apo-B mg/dL IDL Phospholipids mg/dL -8.676660e-01 -4.945702e-02 -9.171231e-01 0.00 0.62 0.00 -0.159421 0.000314 0.924008 5.508131e-213
0 Combination: STATINE_C, ASA_C 3 IDL Phospholipids mg/dL IDL Apo-B mg/dL -2.016744e+00 -2.571526e-01 -2.273896e+00 0.00 0.40 0.00 -0.167196 0.000156 0.924008 5.508131e-213
0 Combination: STATINE_C, ASA_C 3 IDL Apo-B mg/dL VLDL-3 Cholesterol mg/dL -4.209265e-01 -4.595491e-01 -8.804755e-01 0.06 0.04 0.00 -0.159421 0.000314 0.617038 1.611023e-54
0 Combination: STATINE_C, ASA_C 3 VLDL-3 Cholesterol mg/dL IDL Apo-B mg/dL -8.971275e-01 -2.784300e-02 -9.249705e-01 0.00 0.90 0.00 -0.104865 0.018182 0.617038 1.611023e-54
0 Combination: STATINE_C, ASA_C 3 IDL Phospholipids mg/dL observed species richness -1.307090e-01 -2.154356e+00 -2.285065e+00 0.02 0.00 0.00 -0.167196 0.000156 -0.090165 4.242488e-02
0 Combination: STATINE_C, ASA_C 3 IDL Phospholipids mg/dL VLDL-3 Cholesterol mg/dL -1.086558e+00 -1.030593e+00 -2.117151e+00 0.04 0.00 0.00 -0.167196 0.000156 0.755560 7.935187e-95
0 Combination: STATINE_C, ASA_C 3 VLDL-3 Cholesterol mg/dL IDL Phospholipids mg/dL -1.052931e+00 1.652615e-01 -8.876694e-01 0.00 0.48 0.02 -0.104865 0.018182 0.755560 7.935187e-95
0 Combination: STATINE_C, ASA_C 3 observed species richness unclassified Oscillibacter (CAG00961) 2.820528e+00 1.182184e+01 1.464236e+01 0.02 0.04 0.00 0.105616 0.017365 0.487213 1.390025e-31
0 Combination: STATINE_C, ASA_C 3 unclassified Oscillibacter (CAG00961) observed species richness 1.080157e+00 6.960158e+00 8.040316e+00 0.02 0.00 0.00 0.155978 0.000423 0.487213 1.390025e-31
0 Combination: STATINE_C, CA2_CBL_C 3 VLDL Cholesterol mg/dL VLDL-3 Cholesterol mg/dL -3.372228e+00 1.597647e-01 -3.212463e+00 0.04 0.66 0.08 -0.087667 0.048506 0.966398 4.200469e-300
0 Combination: STATINE_C, CA2_CBL_C 3 VLDL-3 Cholesterol mg/dL VLDL Cholesterol mg/dL -6.337151e-01 -5.854321e-02 -6.922583e-01 0.02 0.44 0.06 -0.094016 0.034312 0.966398 4.200469e-300
0 Combination: STATINE_C, CA2_CBL_C 3 VLDL Cholesterol mg/dL Alistipes sp. (motu_linkage_group_621) -3.306795e-01 -2.853797e+00 -3.184477e+00 0.08 0.04 0.04 -0.087667 0.048506 -0.065508 1.407599e-01
0 Combination: STATINE_C, CA2_CBL_C 3 Alistipes sp. (motu_linkage_group_621) VLDL Cholesterol mg/dL 3.966132e+07 5.971176e+08 6.367789e+08 0.04 0.02 0.02 0.111479 0.012013 -0.065508 1.407599e-01
0 Combination: STATINE_C, CA2_CBL_C 3 VLDL-3 Cholesterol mg/dL Alistipes sp. (motu_linkage_group_621) -8.015543e-02 -5.956775e-01 -6.758330e-01 0.06 0.04 0.04 -0.094016 0.034312 -0.066994 1.319529e-01
In [8]:
# Uncomment to print to file
medres_df.to_csv(fileFolder  + 'mediation_results_drug_combination.csv', 
                 index=0)    
In [9]:
import pkg_resources
import sys

#print package versions
print('Sesssion info:')
print('Python: ', sys.version)
print('numpy: ', pkg_resources.get_distribution('numpy').version)
print('pandas: ', pkg_resources.get_distribution('pandas').version)
print('scipy: ', pkg_resources.get_distribution('scipy').version)
print('statsmodels: ', pkg_resources.get_distribution('statsmodels').version)
Sesssion info:
Python:  3.7.7 (default, Apr 15 2020, 05:09:04) [MSC v.1916 64 bit (AMD64)]
numpy:  1.18.1
pandas:  1.0.3
scipy:  1.6.2
statsmodels:  0.11.0