Python Forum
GroupBy - Sum = Error [datetime64 type does not support sum operations]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GroupBy - Sum = Error [datetime64 type does not support sum operations]
#1
Hi,
Im trying to solve this particular issue.
Im using two columns to display Price and Market.
        lftcolumn, rghtcolumn = st.columns((9, 1))
        with lftcolumn:
            pme_df = filtered_df.groupby(by = ["Market"], as_index = False)["Price"].sum().sort_values(by= ["Price"], ascending=False).reset_index()
            pmefig = px.bar(pme_df, x = "Market", y = "Price", text = ['${:,.2f}'.format(x) for x in pme_df["Price"]],template = "seaborn") 
            pmefig.update_layout(xaxis_title="Market",yaxis_title="Price")
            st.plotly_chart(pmefig,use_container_width=True, height = 200)
        with rghtcolumn:
            # # st.subheader("Percentage")
            st.subheader(' "%" dif')
            procentai = pme_df['Price']
  
            st.write(procentai.pct_change() * 100)
Which is fine - it works but with % column i have numbers instead of Market as index.
Im trying to make Index for this as Market.

            pme_df = filtered_df[["Market", "Price"]]
            pme_df = filtered_df.set_index(["Market", "Price"], inplace=True)
            pme_df = filtered_df.groupby(["Market", "Price"]).sum()
Error:
TypeError: datetime64 type does not support sum operations
            pme_df = filtered_df[["Market", "Price"]]
            pme_df = filtered_df.set_index(["Market", "Price"], inplace=True)
            pme_df = filtered_df.groupby(["Market"])["Price"].sum()
Error:
KeyError: 'Column not found: Price'
            pme_df = filtered_df[["Market", "Price"]]
            pme_df = filtered_df.set_index(["Market", "Price"], inplace=True)
            pme_df = filtered_df.groupby(["Market"]).sum()
Error:
TypeError: datetime64 type does not support sum operations
Market contains market areas( string/object type column) and price ( float)
filtered_df - various columns including date column
Whats causing this issue for me ?
Thank You.
Reply


Messages In This Thread
GroupBy - Sum = Error [datetime64 type does not support sum operations] - by BSDevo - Oct-26-2023, 05:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Bitwise Operations in numpy Sowmya 3 406 Apr-03-2024, 02:51 PM
Last Post: deanhystad
  [Numpy] Load date/time from .txt to 'datetime64' type. water 4 787 Mar-01-2024, 11:16 PM
Last Post: Gribouillis
  Type error in Cross_val_score Vicral 0 1,861 Jul-20-2021, 12:18 PM
Last Post: Vicral
  groupby on var with missing values error zenvega 0 1,823 May-07-2021, 07:40 PM
Last Post: zenvega
  type error array BrianPA 2 2,460 Jan-17-2021, 01:48 PM
Last Post: BrianPA
  How to fill datetime64 field in numpy structured array? AlekseyPython 0 2,325 Oct-20-2020, 08:17 AM
Last Post: AlekseyPython
  Error binding parameter 0 - probably unsupported type. illmattic 7 10,502 Jul-18-2020, 09:32 PM
Last Post: illmattic
  Error Message: TypeError: unhashable type: 'set' twinpiques 4 19,208 May-22-2019, 02:31 PM
Last Post: twinpiques
  Error:unsupported operand type(s) for ** or pow(): 'list' and 'int' mcgrim 3 18,509 Mar-22-2019, 01:29 PM
Last Post: buran
  Type Error Confusion Oliver 4 14,611 Dec-06-2017, 03:20 PM
Last Post: Oliver

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020