Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Create new Column in Dataframe with Modulo of other Column

$
0
0

I would like to create a new column "Day2" which takes the second digit of column named "Days", so if we have Days equal to 35, we would take the number 5 to be in "Day2", I tried this but it's not working:

DF["Day2"] = DF["Days"].where(            DF["Days"] < 10,            (DF["Days"] / 10 % 10).astype(int),        )

It seems it's taking the first digit but never the second one, can someone help?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>