title: using pandas to_datetime() method with correct syntax, Unrecognized value type: str?
body: <p>I'm struggling to use pandas's to_datetime function to convert entries from a csv file into datetime objects, so that I could use them for visualization. It seems like I'm misunderstanding probably something simple about how to create datetime objects or the parameters.</p>
  
  <p>I have a csv file that includes several records of dates, an example of one date/time record (that is, an example of one row of the csv files)...</p>
  
  <pre><code>date_column: 17-Apr-18 # day first (not-zero-padded), month abbrev, year
  hour_and_seconds_column: 23:58:40 # hour, minute zero-padded, second
  </code></pre>
  
  <p>I want to visualize each of the times in this csv file using matplotlib. I was reading documentation and I recall seeing that Matplotlib works well with datetime objects...  so I assumed that I would need to use pandas's to_datetime() method to help me convert each of these date/time records of the csv file.</p>
  
  <p>So I have a method that first reads from the csv file, creates a list of lists where each list is supposed to represent a record from the csv file. I only have it read in 3 records. I am not going to include the code for that because I realyl doubt it's relevant to the issue I'm having, but I added a print statement and it's suggesting to me that the records are getting read and saved in the list correctly... Here's the example of three records</p>
  
  <pre><code>    time_records = [[ID_IDENTIFIER, '14-Mar-18', '23:58:40'], [ID_IDENTIFIER, '14-Mar-18', '23:58:21'], [ID_IDENTIFIER, '14-Mar-18', '23:57:24']]
  </code></pre>
  
  <p>(ID_IDENTIFIER has an actual id number in the code)</p>
  
  <p>I also figured that because these dates aren't necessarily in python's traditional format for making datetime objects, I would need to use the format parameter when I called pandas's to_datetime() method.  So I made the following string variable to denote format. It's possible I could have written it incorrectly....</p>
  
  <pre><code>    time_format_from_csv_str = time.strftime("%#d-%b-%y %H:%M:%S")
  </code></pre>
  
  <p>So the last part is that I created a for-loop to combine the last two columns of each list in <code>time_records</code>. I'm just going to post the code, but I'm combining the day/time info with the hour/minutes info into a string:</p>
  
  <pre><code>        for each in time_records:
              time_str = str(each[1]) + " " + str(each[2])
              print(time_str)
              a_date_object = pd.to_datetime(time_str, 
                  format=time_format_from_csv_str)
      print(a_date_object)
  </code></pre>
  
  <p>The program crashes once it gets to the line with <code>a_date_object</code>. The error message is kind of long and has two parts.</p>
  
  <pre><code>  Traceback (most recent call last):
        File "C:\Users\biney\AppData\Roaming\Python\Python36\site-packages\pandas\core\tools\datetimes.py", line 377, in _convert_listlike
        values, tz = conversion.datetime_to_datetime64(arg)
        File "pandas\_libs\tslibs\conversion.pyx", line 188, in pandas._libs.tslibs.conversion.datetime_to_datetime64
        TypeError: Unrecognized value type: &lt;class 'str'&gt;
  
    During handling of the above exception, another exception occurred:
  
    Traceback (most recent call last):
        File "basic_content_analysis.py", line 303, in &lt;module&gt;
           main()
        File "basic_content_analysis.py", line 292, in main
           timestamp_date_visualization()
        File "basic_content_analysis.py", line 204, in timestamp_date_visualization
           a_date_object = pd.to_datetime(time_str, dayfirst=True, format=time_format_from_csv_str)
        File "C:\Users\biney\AppData\Roaming\Python\Python36\site-packages\pandas\core\tools\datetimes.py", line 469, in to_datetime
           result = _convert_listlike(np.array([arg]), box, format)[0]
        File "C:\Users\biney\AppData\Roaming\Python\Python36\site-packages\pandas\core\tools\datetimes.py", line 380, in _convert_listlike
           raise e
        File "C:\Users\biney\AppData\Roaming\Python\Python36\site-packages\pandas\core\tools\datetimes.py", line 347, in _convert_listlike
  errors=errors)
        File "pandas\_libs\tslibs\strptime.pyx", line 157, in pandas._libs.tslibs.strptime.array_strptime
          ValueError: time data '14-Mar-18 23:58:40' does not match format '18-Jun-18 17:08:54' (match)
  </code></pre>
  
  <p>At this point I don't know how to fix the problem because I thought  that pd.to_datetime could take in a string as its argument. I also don't see how my string doesn't fit with the format that it has given me.</p>
  
  <p>how can I fix this bug? And ultimately how can I read in entries from my csv file and turn them into datetime objects (since I'm pretty sure that would be the best way for me to be able to use matplotlib to visualize time-data?)</p>