Split timestamp column CSV
Question: I have a CSV file in the following format:

    
    
    name, lat, lon, alt, time
    id1, 40.436047, -74.814883, 33000, 2016-01-21T08:08:00Z
    

I am trying to use Python to split the time into new columns so it looks like
this:

    
    
    name, lat, lon, alt, year, month, day, hour, min, sec
    id1, 40.436047, -74.814883, 33000, 2016,-01,-21, 08, 08, 00
    

I also want to set the amount of places in the float columns to always be set
to 5 decimal places.

This is the script I have so far:

    
    
    import numpy as np
    
    name,lat,lon,alt,time = np.loadtxt(
        'test_track.csv',
        delimiter=',',
        dtype='str',
        skiprows=1,
        unpack = True
        )
    
    
    year = time[0:3]
    print year
    

Unfortunately, instead of parsing the time into year, it prints out the first
full times instead of just the year.


Answer: You should try importing the data with Pandas instead of numpy. Panda read_csv
handles dates quite nicely

try something like this

    
    
    import pandas as pd
    yourData = pd.read_csv(yourData_Path,delimiter = ',',skiprows = 0,
               parse_dates={'time':[-1]},header = 1,na_values = -9999)
    

Pandas also allows you to index by the datetimes which is quite nice :)

