Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set random seed for pd.util.testing.makeDataFrame()?

Tags:

python

pandas

Edit: I figured out that the issue was related to Jupyter notebooks. I can't set the seed globally and get the same result on every run. I have to set the random seed in the code cell with pd.util.testing.makeDataFrame().

Original question: I'm trying to set the random state so I can get reproducible results for the DataFrames made with pandas's pd.util.testing.makeDataFrame().

I've set the random seed for Python and NumPy. Is there another random seed I can set to get reproducible results?

seed = 34

# python
import random
random.seed(seed)

# numpy
np.random.seed(seed)

I've searched SO to no avail.

like image 220
jeffhale Avatar asked Oct 21 '25 12:10

jeffhale


1 Answers

I figured out that the issue was related to Jupyter notebooks. I can't set the seed for the notebook globally and get the same result on every run. I have to set the random seed in the code cell with pd.util.testing.makeDataFrame().

This SO answer helped confirm.

like image 107
jeffhale Avatar answered Oct 23 '25 02:10

jeffhale