0

I am getting the famous

'SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead'

Error when trying to convert a hexadecimal timestamp column to datetime format.

Here is the code that produced the error:

df.loc[:, 'time']=df['time'].apply(lambda x:datetime.datetime.fromtimestamp(int(x,16)))

also

df['time'] = df['time'].apply(lambda x: datetime.datetime.fromtimestamp(int(x,16))) 

an example timestamp I am trying to converted is '5d856af7'

Is there any way to perform this operation without a warning. Other code snippets i have tried without success are:

df['time'] = pd.to_datetime(df['time']).apply(lambda x: int(x,16)))
df['time'] = pd.to_datetime(df['time']).apply(lambda x: int(x,16)))

Any help much appreciated

Thanks!

JDraper
  • 349
  • 2
  • 11
  • Related question: https://stackoverflow.com/questions/41783003/how-do-i-convert-timestamp-to-datetime-date-in-pandas-dataframe – JDraper Oct 31 '19 at 11:00
  • @jezrael I am confused as to why this question was marked a duplicate? Does my code above have chained indexing? – JDraper Oct 31 '19 at 11:07
  • yop, I think there is some filtering before your code and it is reason for errror. If show your code completely, I can exactly says where is problem. Your solution in question is nice, problem is in code above. – jezrael Oct 31 '19 at 11:08
  • 1
    @jezrael My mistake, df was a subset of a larger dataframe. Thanks for your help – JDraper Oct 31 '19 at 11:11

0 Answers0