Pandas dataframe dtypes compare equality

How can I see which dtypespandas is not equal in the data frame?

those. to find out why df1.dtypes.equals(df2.dtypes)returnsFalse

+4
source share
1 answer

As long as the column names match and you have the same number of columns, you can simply compare dtypesdirectly:

In [152]:
df1 = pd.DataFrame({'int':np.arange(5), 'flt':np.random.randn(5)})
df2 = pd.DataFrame({'int':np.random.randn(5), 'flt':np.random.randn(5)})
df1.dtypes == df2.dtypes

Out[152]:
flt     True
int    False
dtype: bool
+3
source

Source: https://habr.com/ru/post/1668514/


All Articles