vendredi 26 janvier 2018 à 10:36

Making Sure DataFrames Have Same Columns in Pandas

Par Eric Antoine Scuccimarra

Python code to make sure two data frames have the same columns in the same order. I used this to make sure that two dataframes had the same dummy columns after using pd.get_dummies:

missing_cols = set( X1.columns ) - set( X2.columns )
for c in missing_cols:
    X2[c] = 0
X2 = X2[X1.columns]

Libellés: coding, python, machine_learning


Commentaires

Connectez-vous ou Inscrivez-vous pour enregistrer un commentaire..


Archives du Blogue