Skip to content

Instantly share code, notes, and snippets.

@escuccim
Created January 28, 2018 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save escuccim/3539f682df7585bde14f2b40049f5cae to your computer and use it in GitHub Desktop.
Save escuccim/3539f682df7585bde14f2b40049f5cae to your computer and use it in GitHub Desktop.
Code to sync columns for two pandas dataframes
# For two dataframes X1 and X2, sync columns in X2 to be same as X1 in same order.
missing_cols = set( X1.columns ) - set( X2.columns )
for c in missing_cols:
X2[c] = 0
X2 = X2[X1.columns]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment