0

UPDATE: See the code below that produced the column I have in my screen shot

df_EVENT5_5['age'] = dt.datetime.now().date() - df_EVENT5_5['dt_old']
df_EVENT5_5['age_no_days'] = df_EVENT5_5['age'].dt.total_seconds()/ (24 * 60 * 60)

I have a calculated column that's the subtraction of two datetime columns. The end result looks like below:

enter image description here

I want to completely remove the timestamp from the field. How can I do that? Any help is greatly appreciated.

Below is the code I tried

remove_timestamp_col = ['COL_1', 'COL_2']

    for i in remove_timestamp_col:
        df_EVENT5_13[i] = df_EVENT5_13[i].age.days()
PineNuts0
  • 4,740
  • 21
  • 67
  • 112

1 Answers1

0

Try something like that:

string = "9716 days 00:00:00.000000000"

print(string.split(' ', 1)) # split string into words and space is the separator

print(string.split(' ', 1)[0]) # [0] means print first field from dictionary, if you change it to 1 your result will be days 00:00:00.000000000

result = string.split(' ', 1)[0] # comment or remove print lines if you don't want them

Output:

['9716', 'days 00:00:00.000000000']

9716

Slawek
  • 13
  • 4
  • what if I don't want to print ? still want to keep it as a dataframe – PineNuts0 Nov 10 '17 at 19:29
  • Can you show the code for the current output? What is the code like to get that list? – Slawek Nov 10 '17 at 21:05
  • Please see my updated question above that shows the code you are asking for ... thx – PineNuts0 Nov 12 '17 at 20:28
  • del df['column_name'] or df = df.drop('column_name', 1) Maybe that link will help more: (https://stackoverflow.com/questions/13411544/delete-column-from-pandas-dataframe-using-python-del?rq=1) – Slawek Nov 15 '17 at 17:57