I have a csv file with 5 columns, in which the second column is time represented in format 10/22/2001 14:00. I want to create another file with this time data split into separate columns. To split the column I used the below code in python
from numpy import loadtxt
import numpy as np
from time import strptime
filename = 'data/file.csv'
data = loadtxt(filename, delimiter=',', dtype=str, skiprows=1)
newdata = np.zeros((data.shape[0],7))
newdata[:,0] = data[:,0]
for i in range(len(data[:,1])):
tm = strptime(data[i,1], "%m/%d/%Y %H:%M")
newdata[i,1] = tm.tm_year
newdata[i,2] = tm.tm_wday
newdata[i,3] = tm.tm_hour
newdata[:,4:] = data[:,2:]
Is there a better way of doing this using numpy methods or other modules of python?