julian joseph
julian joseph

Reputation: 330

How to create data frame of random floating point numbers with Pandas

pd.DataFrame(np.random.randint(0,253,size=(253, 830)), columns=list_cols)

I used this for getting random integers but i needed floating point numbers instead. Any idea how?

Upvotes: 7

Views: 14820

Answers (3)

Pouya Esmaeili
Pouya Esmaeili

Reputation: 1263

You can use numpy.random.uniform to create dataframe with floating numbers between a and b.

pd.DataFrame(np.random.uniform(0, 1, size=(253, 830)), columns=list_cols)

Upvotes: 4

Anake
Anake

Reputation: 7659

randint generates random integers. Use rand to get random numbers between 0 and 1. You can then multply that by the maximum value you want. (which I guess is 254 rather than 253).

pd.DataFrame(np.random.rand(253, 830) * 254, columns=list_cols)

Upvotes: 10

Ravi kumar
Ravi kumar

Reputation: 171

import numpy as np
import pandas as pd


## Let's create 5000 rows and 4 different columns
arr_random = np.random.default_rng().uniform(low=5,high=10,size=[5000,4])
arr_random

## Creating the dataframe
df = pd.DataFrame(arr_random, columns=["A","B","C","D"])

Upvotes: 0

Related Questions