0

I try to substract two pandas series which contain no. of flights for each day between passed dates. When i substract them i get series with length 132858. Why is that? I'd like to substract every paired date.

flights2019 = flights('2019-01-01','2020-01-01')
flights2020 = flights('2020-01-01','2021-01-01')
flightsDiff = flights2019.sub(flights2020)
print(flightsDiff.size)

Edit: My series seem to not be numbered. Could this be source of the problem? How do I fix this?

enter image description here

Gašper Štepec
  • 115
  • 1
  • 1
  • 7
  • 2
    [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – It_is_Chris Jan 11 '22 at 15:49
  • 2
    What is `flights()`? By "subtract dates" do you mean determine the time interval in days between two dates? Please see [mcve]. – msanford Jan 11 '22 at 15:50
  • flights() is a function that gets data from local database. I receive number of flights for each day and i would like to get the difference of no. of flights for each day between 2020 and 2019 – Gašper Štepec Jan 11 '22 at 15:51
  • 1
    pandas aligns indexes when subtracting and 363*366 = 132858. –  Jan 11 '22 at 15:52
  • 1
    How do you plan to subtract two series with different length? What's your expected output? –  Jan 11 '22 at 15:53
  • It seems like I don't have data for two days in 2019. I'll check it out. Afaik it should still subtract if they're indexed - it then subtracts based on indeces and if no pairing for index can be found the value won't be subtracted by anything – Gašper Štepec Jan 11 '22 at 15:54
  • 1
    Yeah but the index of both seems to be all zeros, hence 363*366. –  Jan 11 '22 at 15:55
  • 2
    If you do `flights2019 = flights2019.reset_index(drop=True)` and the similar for the other one, the result might be more meaningful. This resets the index to 0..N-1. –  Jan 11 '22 at 15:56
  • 1
    Yeah, index array wasn't configured. Thank you! – Gašper Štepec Jan 11 '22 at 15:57

0 Answers0