Skip to content Skip to sidebar Skip to footer

Removing Incomplete Years From Pandas Dataframe

I want to remove incomplete years from a dataframe to analyse the complete years further. I've looked here but the question is old and unresolved. This post follows on from a previ

Solution 1:

Get the years and pass to your original df and call isin and pass dt.year:

In [93]:years=count[count['date']>=365].indexdf[df['date'].dt.year.isin(years)]Out[93]:dateA02007-01-01  0.02074512007-01-02  0.03002422007-01-03 -0.38579332007-01-04 -0.73772042007-01-05  0.08970752007-01-06 -0.82014162007-01-07 -0.08174072007-01-08  0.23326582007-01-09  1.33622492007-01-10  0.570297102007-01-11 -0.280080112007-01-12 -1.582950122007-01-13  0.494927132007-01-14  2.065250142007-01-15 -2.406877152007-01-16  0.124046162007-01-17 -1.015604172007-01-18  1.480173182007-01-19  0.705919192007-01-20 -2.014657202007-01-21  0.130874212007-01-22 -0.138736222007-01-23  1.874702232007-01-24 -0.170154242007-01-25 -1.548015252007-01-26 -0.878455262007-01-27 -0.871497272007-01-28  1.992482282007-01-29  0.565247292007-01-30  1.257662.........2892 2014-12-02 -1.0522772893 2014-12-03  0.1230172894 2014-12-04 -0.9709472895 2014-12-05 -0.8212082896 2014-12-06 -0.0271182897 2014-12-07 -0.1000332898 2014-12-08  0.9547332899 2014-12-09  0.3889982900 2014-12-10  0.6674432901 2014-12-11  1.5808042902 2014-12-12  0.7240112903 2014-12-13 -2.1565072904 2014-12-14  0.7362362905 2014-12-15  0.8636742906 2014-12-16 -0.2049922907 2014-12-17  0.9763072908 2014-12-18  1.4563672909 2014-12-19 -0.5168542910 2014-12-20 -0.1402912911 2014-12-21  1.4672252912 2014-12-22  0.9575422913 2014-12-23  2.0614772914 2014-12-24  0.2021042915 2014-12-25  0.8061402916 2014-12-26 -0.4783802917 2014-12-27  1.1091582918 2014-12-28 -0.5984172919 2014-12-29 -1.2839222920 2014-12-30  0.5463902921 2014-12-31 -0.640812

[2922 rowsx2columns]

This will filter the df so that only those dates with full complement of days remain

Post a Comment for "Removing Incomplete Years From Pandas Dataframe"