Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Randow DataFrame
#1
Hey guys !

I was trying to make a 4*54 random numbers DataFrame. I spent 1 hour trying to figure out how to do it and I wrote this code :
import pandas as pd
from random import randint
df = pd.DataFrame()
for i in range(53):
    data1 = pd.DataFrame([randint(1,3)])
    data2 = pd.DataFrame([randint(1,3)])
    data3 = pd.DataFrame([randint(1,3)])
    data4 = pd.DataFrame([randint(1,3)])
    data = pd.DataFrame(pd.concat([data1, data2, data3, data4], axis =1, join_axes=[data1.index]))

    df = df.append(data, ignore_index = True)
I'm satisfied with the result but I think there should be a better way to do it.

What do you think about it ? :)

Have a nice day all !
Reply


Messages In This Thread
Randow DataFrame - by ArnaudCoulon - Feb-02-2018, 04:59 PM
RE: Randow DataFrame - by ka06059 - Feb-03-2018, 12:19 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020