Plotting timestamps in Python
<p>I am new to Python and am trying to create a simple line graph with time on the x axis and values on the y. I have a CSV file from which to import the data.</p>

<p>A sample of the data looks like this</p>

<p><a href="http://i.stack.imgur.com/GIygc.png" rel="nofollow"><img src="http://i.stack.imgur.com/GIygc.png" alt="Data Extract"></a></p>

<p>I have tried to use the following code:</p>

<pre><code>    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    a_data = pd.read_csv("Data Sampler.csv")
    plt.plot(a_data.Timestamp, a_data.a)
</code></pre>

<p>However, I am receiving an error message: AttributeError: 'Series' object has no attribute 'find'</p>

<p>a_data.dtypes tells me that Timestamp is an object and A is float 64.</p>

<p>Can anyone help? From googling a solution, it looks like I need to convert the timestamp to a datetime within Python - however I am not having much luck with this (lots of error messages).</p>

<p>Thanks in advance.</p>

<p>If you're using <code>matplotlib.__version__ &gt;= 1.5.0</code>, then the following should work:</p>

<pre><code>In [4]: df
Out[4]: 
          Timestamp         A
0  03/10/2016 16:00  0.033361
1  04/10/2016 16:01  0.123108
2  05/10/2016 16:02  0.021805

In [5]: df.index = pd.to_datetime(df.Timestamp, dayfirst=True)

In [6]: df
Out[6]: 
                            Timestamp         A
Timestamp                                      
2016-10-03 16:00:00  03/10/2016 16:00  0.033361
2016-10-04 16:01:00  04/10/2016 16:01  0.123108
2016-10-05 16:02:00  05/10/2016 16:02  0.021805

In [7]: plt.plot('A', data=df)
Out[7]: [&lt;matplotlib.lines.Line2D at 0x7f8e3c0e8150&gt;]

In [7]: plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/kkRLe.png" rel="nofollow"><img src="http://i.stack.imgur.com/kkRLe.png" alt="enter image description here"></a></p>

<p>Depending on the scale of your data, you can adjust the tick formatting of the x-axis using the appropriate tick formatters, see <a href="http://matplotlib.org/examples/pylab_examples/date_demo2.html" rel="nofollow">here</a> for an example.</p>

python datetime matplotlib timestamp