I am trying to take a pandas DataFrame, take out 1 column, shuffle the contents of that column, and then put it back in 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 result every time I run it. Why is this?
Note. I use the same data file every time.
source
share