I need help removing unwanted zeros from a data frame. The column values are integers and I'm not exactly sure how to remove the zeros from the 'Year' column. As shown in the image below, (highlighted in blue), I'm trying to remove the zeros after '2014'. (there are a few other values like this in this column)
You can filter first 4 values in column Year
by converting to strings with str[:4]
:
df['Year'] = df['Year'].astype(str).str[:4].astype(int)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.