mardi 9 octobre 2018

1 Milllion Integers GroupBy - Occurrence

I created 1million random integers between 1 and 100 & wrote the results to a text file.

Results_File = open('RandomResults.txt','w')
for i in range(1000000):
    x = random.randint(1,100)
    Results_File.write(str(x) + "," + '\n')

Okay that works. But I wanted to find the occurrence of each integer in the entire dataset.

So I imported the file into a new python session and created a dataframe from the data. ( I also opened the csv & created the header column "A" to help with moving the data around in Pandas. ( probably wasn't needed)

  df = pd.read_csv('RandomNumbers.csv','r') 
  df.sort_values(by=['A'])

This is where i'm stuck. Could someone point me into the right direction?

I want to see how often each number occurs in this random distribution of numbers.




Aucun commentaire:

Enregistrer un commentaire