Home > Blockchain >  Random number to dataframe
Random number to dataframe

Time:03-28

I want to make a dataframe using random number from 1 to 200.

how do I make a dataframe?

column number is one row number is two hundred.

CodePudding user response:

IIUC, use numpy:

import pandas as pd
import numpy as np

# All numbers between 1 and 200
data1 = np.random.permutation(np.arange(1, 201))
df1 = pd.DataFrame({1: data1})

# 200 numbers between 1 and 200
data2 = np.random.randint(1, 201, 200)
df2 = pd.DataFrame({1: data2})

CodePudding user response:

This should work

import pandas as pd
import random

data = [random.randrange(1, 200) for i in range(200)]
df = pd.DataFrame(data, columns = ['random_number'])

It will create a list of random numbers with length=200 filled with random numbers from 1 to 200 and then create a dataframe with those values in one column called 'random_number'

  • Related