using groupby on pandas dataframe to group by financial year

newbie

I have a dataframe with a datetime64 column called DT. Is it possible to use groupby to group by financial year from April 1 to March 31?

For example,

    Date | PE_LOW 
    2010-04-01 | 15.44
    ...
    2011-03-31 | 16.8
    2011-04-02 | 17.
    ...
    2012-03-31 | 17.4

For the above data, I want to group by Fiscal Year 2010-2011 and Fiscal Year 2011-2012 without creating an extra column.*

Jihun

With pandas.DatetimeIndex, that is very simple:

DT.groupby(pd.DatetimeIndex(DT.Date).shift(-3,freq='m').year)

Or if you use Date as an index of DT, it is even simpler:

DT.groupby(DT.index.shift(-3,freq='m').year)

But beware that shift(-3,freq='m') shifts date to ends of months; for example, 8 Apr to 31 Jan and so on. Anyway, it fits your problem well.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

using groupby on pandas dataframe to group by financial year

From Dev

pandas dataframe interpolate for Nans with groupby using window of discrete days of the year

From Dev

SQL group data by financial year

From Dev

SQL group data by financial year

From Java

How to group dataframe rows into list in pandas groupby

From Dev

Pandas Dataframe GroupBy - Displaying Group Statistics

From Dev

Pandas: DataFrame groupby for year/month and return with new DatetimeIndex

From Dev

GroupBy operation using an entire dataframe to group values

From Dev

Pandas groupby month and year

From Dev

Pandas DataFrame with MultiIndex: Group by year of DateTime level values

From Dev

Calculate STD manually using Groupby Pandas DataFrame

From Dev

Pandas: DataFrame filtering using groupby and a function

From Dev

Calculate STD manually using Groupby Pandas DataFrame

From Dev

pandas groupby of DataFrame using Series of substrings

From Dev

Calculating group average and assigning it to sub-group using Pandas groupby

From Dev

Python Pandas, setting groupby() group labels as index in a new dataframe

From Dev

update pandas.DataFrame within a group after .groupby()

From Dev

How to group and count rows by month and year using Pandas?

From Dev

Find the majority in dataframe using pandas.DataFrame.mode and groupby

From Dev

Break a dataframe into several dataframes by using groupby and get_group

From Dev

Zipline: using pandas-datareader to feed in Google Finance dataframe for non-US based financial markets

From Dev

Pandas groupby year object plotting it year over year

From Dev

Pandas groupby year object plotting it year over year

From Dev

Combining quarter and financial year columns into date column in pandas

From Java

Get statistics for each group (such as count, mean, etc) using pandas GroupBy?

From Java

Unstack Groupby does not group the data in proper dataset using Pandas

From Java

Check if all elements in a group are equal using pandas GroupBy

From Dev

In Pandas, how to apply a customized function using Group mean on Groupby Object

From Dev

Check if all elements in a group are equal using pandas GroupBy

Related Related

  1. 1

    using groupby on pandas dataframe to group by financial year

  2. 2

    pandas dataframe interpolate for Nans with groupby using window of discrete days of the year

  3. 3

    SQL group data by financial year

  4. 4

    SQL group data by financial year

  5. 5

    How to group dataframe rows into list in pandas groupby

  6. 6

    Pandas Dataframe GroupBy - Displaying Group Statistics

  7. 7

    Pandas: DataFrame groupby for year/month and return with new DatetimeIndex

  8. 8

    GroupBy operation using an entire dataframe to group values

  9. 9

    Pandas groupby month and year

  10. 10

    Pandas DataFrame with MultiIndex: Group by year of DateTime level values

  11. 11

    Calculate STD manually using Groupby Pandas DataFrame

  12. 12

    Pandas: DataFrame filtering using groupby and a function

  13. 13

    Calculate STD manually using Groupby Pandas DataFrame

  14. 14

    pandas groupby of DataFrame using Series of substrings

  15. 15

    Calculating group average and assigning it to sub-group using Pandas groupby

  16. 16

    Python Pandas, setting groupby() group labels as index in a new dataframe

  17. 17

    update pandas.DataFrame within a group after .groupby()

  18. 18

    How to group and count rows by month and year using Pandas?

  19. 19

    Find the majority in dataframe using pandas.DataFrame.mode and groupby

  20. 20

    Break a dataframe into several dataframes by using groupby and get_group

  21. 21

    Zipline: using pandas-datareader to feed in Google Finance dataframe for non-US based financial markets

  22. 22

    Pandas groupby year object plotting it year over year

  23. 23

    Pandas groupby year object plotting it year over year

  24. 24

    Combining quarter and financial year columns into date column in pandas

  25. 25

    Get statistics for each group (such as count, mean, etc) using pandas GroupBy?

  26. 26

    Unstack Groupby does not group the data in proper dataset using Pandas

  27. 27

    Check if all elements in a group are equal using pandas GroupBy

  28. 28

    In Pandas, how to apply a customized function using Group mean on Groupby Object

  29. 29

    Check if all elements in a group are equal using pandas GroupBy

HotTag

Archive