I am reading a csv file with German date format. Seems like it worked ok in this post:
Picking dates from an imported CSV with pandas/python
However, it seems like in my case the date is not recognized as such. I could not find any wrong string in the test file.
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib import style
from pandas import DataFrame
style.use('ggplot')
df = pd.read_csv('testdata.csv', dayfirst=True, parse_dates=True)
df[:5]

This results in:

So, the Column with the dates is not recognized as such. What am I doing wrong here? Or is this date format simply not compatible?
- OSX 10.10.3
- Anaconda conda 3.13.0
- Python 3.4.3-0
- iPython notebook 3.1.0
If you use
parse_dates=Truethenread_csvtries to parse the index as a date. Therefore, you would also need to declare the first column as the index withindex_col=[0]:Alternatively, if you don't want the
Datumcolumn to be an index, you could useparse_dates=[0]to explicitly tellread_csvto parse the first column as dates:Under the hood
read_csvusesdateutil.parser.parseto parse date strings:Since
dateutil.parserhas no trouble parsing date strings inDD.MM.YYYYformat, you don't have to declare a custom date parser here.