Skip to main content
Source Link

A possibility in the following code snippet.

import pandas as pd 
import numpy as np
df = pd.DataFrame()
mean = [0,1,2]
scale = [1,2,3]
max_val = [2,3,4]
min_val = [-2,-1,0]
for n in range(3):
    df[n] =  np.random.normal(loc=mean[n],scale=scale[n], size=100)
    df.loc[df[n] < min_val[n],n]= min_val[n]
    df.loc[df[n] > max_val[n],n]= max_val[n]
print('The Dataframes mean is: ',df.mean().mean())

A possibility in the following code snippet.

import pandas as pd 
import numpy as np
df = pd.DataFrame()
mean = [0,1,2]
scale = [1,2,3]
for n in range(3):
    df[n] =  np.random.normal(loc=mean[n],scale=scale[n], size=100)
print('The Dataframes mean is: ',df.mean().mean())

A possibility in the following code snippet.

import pandas as pd 
import numpy as np
df = pd.DataFrame()
mean = [0,1,2]
scale = [1,2,3]
max_val = [2,3,4]
min_val = [-2,-1,0]
for n in range(3):
    df[n] =  np.random.normal(loc=mean[n],scale=scale[n], size=100)
    df.loc[df[n] < min_val[n],n]= min_val[n]
    df.loc[df[n] > max_val[n],n]= max_val[n]
print('The Dataframes mean is: ',df.mean().mean())
Source Link

A possibility in the following code snippet.

import pandas as pd 
import numpy as np
df = pd.DataFrame()
mean = [0,1,2]
scale = [1,2,3]
for n in range(3):
    df[n] =  np.random.normal(loc=mean[n],scale=scale[n], size=100)
print('The Dataframes mean is: ',df.mean().mean())