Skip to content

Instantly share code, notes, and snippets.

@nekketsuuu
Last active July 21, 2017 05:29
Show Gist options
  • Save nekketsuuu/539e353095234956be3adffd63a7d26a to your computer and use it in GitHub Desktop.
Save nekketsuuu/539e353095234956be3adffd63a7d26a to your computer and use it in GitHub Desktop.
Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 12:22:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import pandas as pd
>>> test = pd.DataFrame(np.random.choice([0.0, 100.0], size=(4, 4)))
>>> test
0 1 2 3
0 0.0 0.0 100.0 100.0
1 100.0 100.0 0.0 100.0
2 0.0 100.0 100.0 100.0
3 100.0 100.0 100.0 100.0
>>> train = pd.DataFrame(np.random.rand(4, 4))
>>> train
0 1 2 3
0 0.435729 0.543282 0.911146 0.394409
1 0.693686 0.955173 0.729586 0.808441
2 0.155083 0.327989 0.405951 0.854187
3 0.623706 0.349019 0.286164 0.626817
>>> test = test.where(test == 0, train)
>>> test
0 1 2 3
0 0.000000 0.000000 0.911146 0.394409
1 0.693686 0.955173 0.000000 0.808441
2 0.000000 0.327989 0.405951 0.854187
3 0.623706 0.349019 0.286164 0.626817
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment