1

I am currently learning Python language for Data Science. While Practicing some of the problems I came across a year related problem with Python.

I have a dataframe in datelooks like

0   2061-01-01  
1   2061-01-02  
2   2061-01-03  
3   2061-01-04  
.
.
.
8   1978-12-29      
9   1978-12-30
10  1978-12-31  

I am required to convert the years 2061 to 1961.

Here is what I tried

def check( x ):  
    if (x > 1978):  
        x=x-100 
        print(x)
    else:  
        print(x) 

S1=S1.apply(check)
S1

For some reason, the function is running fine but when I am trying to apply it on the series S1, I am getting output with values None in place of the corrected date

Kindly suggest where I am getting wrong.

Thanks

Bruno Mello
  • 4,448
  • 1
  • 9
  • 39
Sagar
  • 11
  • 2
  • If still problem, please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Apr 02 '20 at 11:39
  • The obvious thing I can see is that you need to `return x` rather than `print(x)` in your function `check()`. `print(x)` merely prints the value and returns `NONE` – tidakdiinginkan Apr 02 '20 at 19:48

0 Answers0