Column Types
Column Types: Column Types: dtypes and astype, Turning Text into Numbers: to_numeric.
Updated
- Column Types: dtypes and astype (Apprentice): Every pandas column has one dtype that decides what its values can do, dtypes lists them (int64, float64, str, bool, datetime64, category), astype changes a column's type, and astype stops on text such as '59 lbs' because it can't guess which part is the number.
- Turning Text into Numbers: to_numeric (Apprentice): Text such as '59 lbs' and '$75' becomes numbers in two steps, .str.replace to take off the units and symbols, then pd.to_numeric with errors='coerce' to convert what's left, followed by a list of the values that became missing so none is lost silently.