0
datetype=['Date received', 'Date sent to company', 'Date']
cols=[] 
for col in datetype:
   cols.append(col)
   for i in range(len(datatype)):
       if (col!=datetype[i]):
          name=col+"_"+datetype[i]
          df[name]=df[col]-df[datetype][i]

Date received, Date sent to company and Date all these contain dates. I was trying to find a difference between these fields. for instance, we have 3 columns date received, Date sent to company and Date. Then you will form 3 new columns containing difference of these dates by taking 2 dates at a time. I am getting an error KeyError: 1

I am new to python programming any help would be appreciated

NinjaWarrior
  • 11
  • 1
  • 1
  • 4
  • 2
    To make your question clear, you have to provide example data and what your expected output is. – Erfan Jun 20 '20 at 11:39
  • This will give you idea: https://stackoverflow.com/questions/22923775/calculate-pandas-dataframe-time-difference-between-two-columns-in-hours-and-minu – Pygirl Jun 20 '20 at 11:46
  • https://stackoverflow.com/questions/46222988/getting-difference-in-two-datetime-columns-in-pandas-dataframe and https://stackoverflow.com/questions/13143050/calculating-subtractions-of-pairs-of-columns-in-pandas-dataframe – Pygirl Jun 20 '20 at 11:47

0 Answers0