I have a column in the python data frame which has values like below
I am looking to convert the ISO format in minutes The output should be :
- 15 minutes
- 90 minutes
- 5 minutes
import pandas as pd
import re
import json
from datetime import datetime
currentdate=datetime.today().strftime('%Y/%m/%d')
absolutepath='/project/sniper/'+'/'+currentdate+'/*.json'
df = pd.read_json('absolutepath', lines=True)
df_sugar = df.loc[df['ingredients'].str.contains("Sugar|sugar", case=True)]
def convertToInteger(my_str):
if 'H' in my_str and PT in my_str:
characters_to_remove_H = "H"
for l in characters_to_remove_H:
new_string_hour = my_str.replace(l, "*60")
new_p=int(new_string_hour.replace(PT,""))
return pd.Series(new_p)
elif 'M' in my_str and PT in my_str:
characters_to_remove_M = "PTM"
for m in characters_to_remove_M:
new_string_minute = int(my_str.replace(m, ""))
return pd.Series(new_string_minute)
df2[["new_col_2"]] = df_beef["prepTime"].apply(convertToInteger)