python - Unable to convert to datetime using pd.to_datetime -
I am trying to read a CSV file and use it as a time frame to convert it into datafree I am CSV file of this type:
# on time CO_T1_AHU.01_CC_CTRV_CHW__SIG_STAT 0 NaN NaN% 1 Nain Nain cooling coil Hydronic Valves Status 2 2014-01-01 00:00:00 0 3 2014 - 01-01 01:00:00 0 4 2014-01-01 02:00:00 0 5 2014-01-01 03:00:00 0 6 2014-01-01 04:00:00 0
< / Pre>I have read using this file:
df = pd.read_csv ('filepath / file.csv', sep = ';', parse_dates = [[0 , 1]]
produced this result:
#Date_Time FCO_T1_AHU.01_CC_CTRV_CHW__SIG_STAT 0 no, 1% Ninan cooling coil Hydronic valve position 2 2014-01 - 01 00:00:00 0 3 2014-01-01 01:00:00 0 4 2014-01-01 02:00:00 0 5 2014-01-01 03:00:00 0 6 2014-01-01 04:00:00 0
To change the string in datetime and continue to use it as an index:
pd.to_datetime (df.values [,, 0]) df.set_index ([Df.column [0]], inplace = true)
get:
FCO_T1_AHU.01_CC_CTRV_CHW__SIG_STAT #Date_Time nan nan% nan nan Cooling Coil Hydronic valve position 2014-01-01 00:00:00 0 01-01-2010 01:00:00 0 01-01-2010 02:00:00 0 01-01-2014 03:00:00 2014-01-01 -01 04:00:00 0
However, pd.to_datetime Unable to convert to datetime. What is the way to find out?
Many thanks louis
string entry 'Nain Nain' to to_datetime Can not be changed by using
, so replace it with an empty string so they can now convert to NaT
:
: Df ['Date_Time']. ( 'Nan Nan', '', inplace = true) df out [122]: Date Time Index CO_T1_AHU.01_CC_CTRV_CHW__SIG_STAT 0 0% 1 1 Cooling Coil Hydronic Valves Status 2 2014-01-01 00:00:00 2 0 3 2014-01-01 01:00:00 3 4 2014-01-01 02:00:00 4 5 5/2014-01-01 03:00:00 5 0 6 2014-01-01 04:00:00 6 in [124]: Df [ 'Date_Time'] = pd.to_datetime (df [ 'Date_Time']) DF-out [124]: Date_Time I Ndex CO_T1_AHU.01_CC_CTRV_CHW__SIG_STAT 0 NaT 0% 1 NaT 1 Cooling coil Hydronic valve position 2 2014- 01-01 00:00:00 2 0 3 2014-01-01 01:00:00 3 4 2014-01-01 02: 00:00 4 5 5 2014-01-01 03:00:00 5:00 6 2014 -01-01 04:00:00 6 0
UPDATE
Actually if you just have coded = True
is set if it is correct Pantrit becomes:
df [ 'Date_Time'] = pd.to_datetime (df [ 'Date_Time'], Corrs = true)
Comments
Post a Comment