0

I want to know the related station code in column 'stasjon-kd' for both maximum and minimum value of the column 'std-tid' which is grouped by tog-nr. I have written the code below. but it gives me error.

def stasjon_fra_to(path):
    stasjon_kd,std_tid = path
    np.where('std_tid' == arr.max(),'stasjon_kd',NA)

std_1['Stajon'] = std_1[['stasjon_kd','std_tid']].apply(stasjon_fra_to)

The error is :

NameError: ("global name 'arr' is not defined", u'occurred at index stasjon_kd')

Although I am not sure if the codes above will lead me to the right answer.

sample of sorted data for train number 44

sanchitarora
  • 882
  • 9
  • 18
Nakisa
  • 1
  • 1
  • 2
    Hi @Nakisa, welcome to Stack Overflow. Could you please post some sample data and the expected result? – Daniel Labbe Mar 17 '19 at 22:17
  • yes, surely. I just added the photo of a sample data sorted by date and train number, this part of the data is for one of the trains-number 44 out of many passing many different stations. – Nakisa Mar 18 '19 at 21:34
  • Hi @Nakisa - welcome to Stack Overflow. I made some edits to make the code more readable. I don't think I completely understand the question but the error in the code seems to be that when you do `arr.max()` the variable `arr` is not defined. Is the intention to find the max value of the `std_tid` column? – sanchitarora Mar 18 '19 at 21:42
  • Hi @Nakisa, please take a look at this thread where the best way to post an example dataset is discussed: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples . When you post images, you are not helping others to reproduce the error you are receiving, and it reduces the chance of someone answer your question. – Daniel Labbe Mar 19 '19 at 11:33

0 Answers0