by switch007 · 5y ago · 0 comments
https://pandas.pydata.org/pandas-docs/stable/reference/api/p... is pretty powerful (see also "parse_dates" and "converters" parameters). See also parse_excel()
You can also use procedural code to look at the column data and change the type:
# if all values in col c2 when converted to string begin with "0" and and values are of length 9, convert to int64
if df["col"].str.match("^0").all() and set(df["col"].str.len()) == {9}:
df["col"] = df["col"].astype("int64")