1
$\begingroup$

I am trying to generate a normally distributed data frame in Python with 3 columns. Each column requires a separate input of mean, standard deviation, lower and upper values. I am trying to generate sales data of Unique Coke products, Unique Products and Total Revenue which are normally distributed. Also, how can I find the mean of the entire normally distributed data frame?

$\endgroup$

1 Answer 1

0
$\begingroup$

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())
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.