1

I've been trying to create a table that has randomly generated data using Pandas and Numpy. I've looked at the cheat sheet for Pandas but still can't get this work

import names
import pandas as pd
import random
import numpy as np

random.seed(100)
currency_numbers = random.sample(range(100000, 1000000), 100)

s = pd.Series(np.random.randn(100))
raw_data = {

    "Names":["".join(names.get_full_name()) for i in range(100)],

    "Names2":["".join(names.get_full_name()) for i in range(100)],

    "Currency":[]

}

df = pd.DataFrame(raw_data, columns=["Names", "Names2", "Currency"])

df.head()

I want to create a column of 100 random numbers under the Currency section?

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
M511
  • 25
  • 1
  • 5
  • https://github.com/pandas-dev/pandas/blob/master/doc/cheatsheet/Pandas_Cheat_Sheet.pdf – Scott Skiles Nov 07 '18 at 14:31
  • `df = pd.DataFrame(np.random.randint(10, 100, size=(10,1)))` does what you are looking for. – Abbas Nov 07 '18 at 14:31
  • Possible duplicate of [How to create a data frame of random integers with Pandas?](https://stackoverflow.com/questions/32752292/how-to-create-a-data-frame-of-random-integers-with-pandas) – m33n Nov 07 '18 at 14:36

2 Answers2

2

Just use the function: np.random.randint()

For example when I call this --> np.random.randint(1000,size=100)

The largest integer to be chosen in the random function is 999 aka anything from [0, 1000) and the size of the array would have a length of 100.

Therefore in your case,

s = np.random.randint(1000,size=100)

then set Currency to s,

"Currency":s

and the resulting DataFrame should give a column with 100 random numbers

JUST FYI, with this function you can also set a low and a high range... So in your case it would be something like this:

s = np.random.randint(100000, 1000000,size=100)
0

Please check whether this helps.

import names
import pandas as pd
import random
import numpy as np

random.seed(100)
currency_numbers = np.random.randint(100000,1000000,size=(1,100))

s = pd.Series(np.random.randn(100))
raw_data = {

    "Names":["".join(names.get_full_name()) for i in range(100)],

    "Names2":["".join(names.get_full_name()) for i in range(100)],

    "Currency":currency_numbers[0]

}

df = pd.DataFrame(raw_data, columns=["Names", "Names2", "Currency"])

df.head()
Adrish
  • 52
  • 1
  • 7