python - In Pandas, how to re-determine the dtypes of columns after dropna? -
i have dataframe df
constructed via read_csv
. want compute statistics on sampled sub_df
. sub_df
, want drop rows missing nans , re-check true types of columns.
in data, many of integer columns read float because of missing values.
i think understand question. don't think can automatically, can manually convert datatype of column using astype
:
import pandas pd import numpy np df = pd.dataframe([np.nan,2,3],columns = ['value']) df.dtypes value float64 dtype: object sub_df = df[df.value.notnull()] sub_df.value = sub_df.value.astype(int) sub_df.dtypes value int32 dtype: object
Comments
Post a Comment