'How can i insert three columns inside 'Percentile' column

I want to add three columns inside that percentile columns but not sure how to do it , any suggestions ?

and this is df=

@status_message_decorator("Refreshing statistics...")
def refresh_statistics(self, force=False):
    if force or self.settings.refresh_statistics.value:
        df = self.df

        d = {"Type": df.dtypes.astype(str),
             "Count": df.count(),
             "N Unique": nunique(df),
             "Mean": df.mean(numeric_only=True),
             "StdDev": df.std(numeric_only=True),
             "Min": df.min(numeric_only=True),
             "Max": df.max(numeric_only=True),

             "Percentile (25%)": df.mean(numeric_only=True) * 25 / 100,
             "Percentile (50%)": df.mean(numeric_only=True) * 50 / 100,
             "Percentile (75%)": df.mean(numeric_only=True) * 75 / 100,
             "kyrtosis": df.max(numeric_only=True),
             "skewness": (3 * (df.mean(numeric_only=True) - df.mean(numeric_only=True) * 50 / 100)) / df.std(
                 numeric_only=True),
             }
        d['Max'] = {'col4': [1, 2], 'col5': [2, 3], 'col6': [4, 5]}
        self.column_statistics = pd.DataFrame(data=d, index=df.columns)

and this df :

[812 rows x 102 columns]
              Type  Count  N Unique  ...  Percentile (75%)   kyrtosis  skewness
0          float64    812       698  ...          0.008219   6.514846  0.017131
1          float64    812       604  ...          0.034848   8.874518  0.064056
2          float64    812        71  ...          0.001846  19.101014  0.003592
3          float64    812       733  ...          0.030433  17.726106  0.050622
4          float64    812       699  ...         -0.037690   4.795342 -0.076286


Solution 1:[1]

For example we have a data frame 'd':

d = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=d)
d

gives : {'col1': [1, 2], 'col2': [3, 4]}

then we want to make it nested a DF.

We can do that by passing that particular column a set of required values,in your case 3 :

for example :

d['col2']= {'col4':[1,2],'col5':[2,3],'col6':[4,5]}
print(d)

gives :

  {'col1': [1, 2], 'col2': {'col4': [1, 2], 'col5': [2, 3], 'col6': [4, 5]}}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 EAZY_EZ_HE