I have a csv file where one of the columns is a date/time string. How do I parse it correctly with pandas
? I don't want to make that column the index. Thanks!
Uri
Use astype() function to convert the string column to datetime data type in pandas DataFrame. The data type of the DateTime isdatetime64[ns] ; should be given as the parameter. Yields same output as above.
In Pandas, you can convert a column (string/object or integer type) to datetime using the to_datetime() and astype() methods.
For non-standard datetime parsing, use pd.to_datetime after pd.read_csv . To parse an index or column with a mixture of timezones, specify date_parser to be a partially-applied pandas.to_datetime() with utc=True . See Parsing a CSV with mixed timezones for more.
To select a single column, use square brackets [] with the column name of the column of interest.
Pass dateutil.parser.parse
(or another datetime conversion function) in the converters
argument to read_csv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With