TransWikia.com

Generating normally distributed data frame with 3 columns

Data Science Asked by NKU on June 21, 2021

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?

One Answer

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())

Answered by Duccio Piovani on June 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP