I have a pandas dataframe like this:
df
Case Type Base
Year
2000 HI PC1 0
2001 HI PC1 0
2003 HI PC1 2.0
2004 HI PC1 0
2005 HI PC2 0
2006 HI PC2 0
2007 HI PC2 2.0
2008 HI PC2 0
2009 LO PC1 0
2010 LO PC1 0
2011 LO PC1 2.0
2012 LO PC1 0
2013 LO PC2 0
2014 LO PC2 0
2015 LO PC2 2
2016 LO PC2 0
I want to replace some of the zero values not all of them in column ['Base'] with value 1, so the final df looks like this:
df
Case Type Base
Year
2000 HI PC1 1
2001 HI PC1 1
2003 HI PC1 2.0
2004 HI PC1 0
2005 HI PC2 1
2006 HI PC2 1
2007 HI PC2 2.0
2008 HI PC2 0
2009 LO PC1 1
2010 LO PC1 1
2011 LO PC1 2.0
2012 LO PC1 0
2013 LO PC2 1
2014 LO PC2 1
2015 LO PC2 2.0
2016 LO PC2 0
I used the code below:
df.groubpy(['Case','Type'].apply(lambda x: x.[0:3,3].replace({0:1})
But I realize I only get the results between 2000 and 2001, not between 2000,2016.
Thank you for your help.