Created
November 15, 2016 16:41
-
-
Save alittlesliceoftom/f55c3cdb2b6b205b0b0ced6a48c94c56 to your computer and use it in GitHub Desktop.
Test DataFrames and Joining Them, Good for testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def test_join(how,a,b,c): | |
x = pd.merge(a,b,on = 'data',how = how) | |
y = pd.merge(a,c,on = 'data',how = how) | |
z = pd.merge(b,c,on = 'data',how = how) | |
xy = pd.merge(x,y,on = 'data', how = how) | |
yz = pd.merge(y,z,on = 'data',how = how) | |
xz = pd.merge(x,z,on = 'data',how = how) | |
print('join options') | |
print (xy) | |
print (xz) | |
print (yz) | |
return xy, xz, yz | |
def data(): | |
a = pd.DataFrame([1,1,2,3,5,8,13,21],columns=['data']) | |
b = pd.DataFrame(list(range(1,22,2)),columns=['data'] ) | |
c = pd.DataFrame(list(range(1,22,3)),columns=['data']) | |
return a,b,c | |
a,b,c = data() | |
for how in ('inner','outer'): | |
test_join(how,a,b,c) | |
xy, xz, yz = test_join('inner',a,b,c) | |
answer = len(a)+len(b) +len(c) - xy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment