I want to add extra raw to my numpy recarray with reformated date.
i have a csv:
<DATE> <TIME> <OPEN> <HIGH> <LOW> <CLOSE> <TICKVOL> <VOL> <SPREAD>
2020.08.17 00:00:00 44.920 44.920 44.900 44.910 4 0 10
2020.08.17 00:01:00 44.910 44.910 44.850 44.860 10 0 10
2020.08.17 00:02:00 44.860 44.870 44.860 44.860 3 0 10
2020.08.17 00:03:00 44.860 44.860 44.850 44.850 2 0 10
My code:
def datetostr(datenp):
ts = pd.to_datetime(str(datenp))
d = ts.strftime('%Y.%m.%d %H:%M:%S')
return d
colnames = ['Date', 'Time', 'Open', 'High', 'Low', 'Close', 'Tickvol', 'Vol', 'Spread']
stocks = pd.read_csv(infile, sep='\t', parse_dates=[['Date', 'Time']], header=0, names=colnames).to_records(index=False)
plotly_date = np.array([datetostr(xi) for xi in stocks['Date_Time']])
In stocks array:
('Date_Time', 'Open', 'High', 'Low', 'Close', 'Tickvol', 'Vol', 'Spread')
initial_array : [('2020-08-14T00:00:00.000000000', 44.96, 45. , 44.94, 44.97, 14, 0, 10)
('2020-08-14T00:01:00.000000000', 44.97, 44.99, 44.92, 44.95, 19, 0, 10)
('2020-08-14T00:02:00.000000000', 44.94, 44.94, 44.89, 44.91, 16, 0, 10)
In plotly_date:
plotly_date_array : ['2020.08.14 00:00:00' '2020.08.14 00:01:00' '2020.08.14 00:02:00' ...
'2020.08.18 20:57:00' '2020.08.18 20:58:00' '2020.08.18 20:59:00']
I want to add a new column to stocks with textformat data, stored in plotly_date
result = np.column_stack((stocks, plotly_date))
It gets me an error:
TypeError: invalid type promotion
What i do wrong? and how to add a new column named "Date" properly?