Skip to content Skip to sidebar Skip to footer

How To Resolve Positional Index Error In Python While Solving A Condition In Python?

I have the following data and I am trying the following code: Name Sensex_index Start_Date End_Date AAA 0.5 20/08/2016 25/09/2016 AAA 0.8

Solution 1:

You probably overwritten your df somewhere:

tsv = """Name    Sensex_index    Start_Date       End_Date
AAA        0.5           20/08/2016    25/09/2016 
AAA        0.8           26/08/2016    29/08/2016 
AAA        0.4           30/08/2016    31/08/2016
AAA        0.9           01/09/2016    05/09/2016
AAA        0.5           12/09/2016    22/09/2016
AAA        0.3           24/09/2016    29/09/2016
ABC        0.9           01/01/2017    15/01/2017
ABC        0.5           23/01/2017    30/01/2017
ABC        0.7           02/02/2017    15/03/2017
"""df=pd.read_table(io.StringIO(tsv), sep="\s+")

then I copy-pasted your code and received no error, but this df

  Name  Sensex_index  Start_Date    End_Date  change Termination_Date  \0  AAA           0.520/08/201625/09/2016NaN31/08/20161  AAA           0.826/08/201629/08/20160.031/08/20162  AAA           0.430/08/201631/08/20161.031/08/20163  AAA           0.901/09/201605/09/20160.029/09/20164  AAA           0.512/09/201622/09/20160.029/09/20165  AAA           0.324/09/201629/09/20161.029/09/20166  ABC           0.901/01/201715/01/2017NaN30/01/20177  ABC           0.523/01/201730/01/20171.030/01/20178  ABC           0.702/02/201715/03/20171.015/03/2017   

  Actual_Start  
020/08/2016120/08/2016220/08/2016301/09/2016401/09/2016501/09/2016601/01/2017701/01/2017802/02/2017

Just recreate your dataframe and you should be good.

Post a Comment for "How To Resolve Positional Index Error In Python While Solving A Condition In Python?"