You can use apply
to iterate through each column using pd.to_datetime
data.iloc[:, 7:12] = data.iloc[:, 7:12].apply(pd.to_datetime, errors="coerce")
As part of the changes in pandas 1.3.0, iloc
/loc
will no longer update the column dtype on assignment. Use column labels directly instead:
cols = data.columns[7:12]
data[cols] = data[cols].apply(pd.to_datetime, errors="coerce")
Related Contents:
- Convert Pandas Column to DateTime
- Converting between datetime, Timestamp and datetime64
- Extracting just Month and Year separately from Pandas Datetime column
- Keep only date part when using pandas.to_datetime
- Filtering Pandas DataFrames on dates
- How to print pandas DataFrame without index
- datetime dtypes in pandas read_csv
- How to change the datetime format in Pandas
- Combine Date and Time columns using pandas
- pandas dataframe groupby datetime month
- Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone
- Calculate Time Difference Between Two Pandas Columns in Hours and Minutes
- how to test if a variable is pd.NaT?
- Converting between datetime and Pandas Timestamp objects
- pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offset
- How to add/subtract time (hours, minutes, etc.) from a Pandas DataFrame.Index whos objects are of type datetime.time?
- How to convert string to datetime format in pandas python?
- Create a day-of-week column in a Pandas dataframe using Python
- Pandas: Subtracting two date columns and the result being an integer
- How to convert columns into one datetime column in pandas?
- Pandas: Convert Timestamp to datetime.date
- Getting min and max Dates from a pandas dataframe
- Find the end of the month of a Pandas DataFrame Series
- How do I properly set the Datetimeindex for a Pandas datetime object in a dataframe?
- Locate first and last non NaN values in a Pandas DataFrame
- python pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working
- Python Pandas Group by date using datetime data
- Pandas: Return Hour from Datetime Column Directly
- Python pandas convert datetime to timestamp effectively through dt accessor
- How to set a variable to be “Today’s” date in Python/Pandas
- Add days to dates in dataframe
- AttributeError: Can only use .dt accessor with datetimelike values
- Get weekday/day-of-week for Datetime column of DataFrame
- How to join two dataframes for which column values are within a certain range?
- datetime to string with series in pandas
- Comparison between datetime and datetime64[ns] in pandas
- Generating random dates within a given range in pandas
- Get total number of hours from a Pandas Timedelta?
- How do I round datetime column to nearest quarter hour
- pandas datetime to unix timestamp seconds
- Splitting timestamp column into separate date and time columns
- Truncate `TimeStamp` column to hour precision in pandas `DataFrame`
- Pandas converting row with unix timestamp (in milliseconds) to datetime
- Subtract a year from a datetime column in pandas
- pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working
- Convert column of date objects in Pandas DataFrame to strings
- Convert Pandas Series to DateTime in a DataFrame
- Converting a datetime column to a string column
- Converting time zone pandas dataframe
- Python pandas integer YYYYMMDD to datetime