What does the 'np.random.randn' function do in the context of creating a DataFrame?

QuestionsQuestions8 SkillsProIntroduction to PandasAug, 06 2025
0304

The np.random.randn function generates random numbers from a standard normal distribution (mean = 0, standard deviation = 1). In the context of creating a DataFrame, it is used to populate the DataFrame with random values.

For example, when you create a DataFrame like this:

df = pd.DataFrame({
    "a": np.random.randn(1000),
    "b": np.random.randn(1000),
    "N": np.random.randint(100, 1000, (1000)),
    "x": "x",
})

Here, np.random.randn(1000) generates 1000 random values for columns 'a' and 'b', which can be used for various analyses or visualizations.

0 Comments

no data
Be the first to share your comment!