Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do conditional date formatting in dataframe

Tags:

python

pandas

csv

I have a CSV file which has date value like "20181029". Note that this column can have blank values as well. I want to convert this column as date - data type like (2018-10-29), for blank columns i want to have blank value in dataframe.

like image 699
Alexsander Avatar asked Apr 30 '26 07:04

Alexsander


1 Answers

Call the read_csv method with the argument parse_dates. The value of this argument should be the name of the column in your csv file that contains the dates:

df = pd.read_csv('myfile.csv', parse_dates=['some_col'])
like image 84
rje Avatar answered May 02 '26 20:05

rje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!