I am attempting to take a pandas DataFrame, take out 1 column, shuffle the contents of that column, then place it back into the DataFrame and return it. This is the code used:
def randomize(self, data, column):
'''Takes in a pandas database and randomizes the values in column.
data is the pandas dataframe to be altered.
column is the column in the dataframe to be randomized.
returns the altered dataframe.
'''
df1 = data
df1.drop(column, 1)
newcol = list(data[column])
np.random.shuffle(newcol)
df1[column] = newcol
return df1
It gives the same output every time I run it. Why is that?
Note: I am using the same dataframe every time.
Aucun commentaire:
Enregistrer un commentaire