pandas-groupby Questions

2

Solved

I have got a bug with: x.field.rolling(window=5,min_periods=1).mean() where x is a pandas.core.groupby.groupby.DataFrameGroupBy object. I tried with the solution proposed in this page. So I did t...
Fearfully asked 4/4, 2019 at 13:28

3

Solved

I have read multiple post similar to my question, but I still can't figure it out. I have a pandas df that looks like the following (for multiple days): Out[1]: price quantity time 2016-06-08 ...
Dioxide asked 30/6, 2017 at 20:39

3

Solved

I have a DataFrame df_things that looks like this and i want to predict the quality of the classification before the training A B C CLASS ----------------------- al1 bal1 cal1 Ship al1 bal1 cal1 S...
Cleanthes asked 30/12, 2018 at 16:5

4

I have a DataFrame with incomplete dates and I only need the date/row of the last day available of each month. I tried using TimeGrouper and take .last() of each group. import pandas as pd idx = [...

6

Solved

I have a DataFrame with a column that has some bad data with various negative values. I would like to replace values < 0 with the mean of the group that they are in. For missing values as NAs, ...
Lactone asked 7/2, 2013 at 20:51

3

I have a geopandas dataframe containing a list of shapely POINT geometries. There is another column with a list of ID's that specifies which unique polygon each point belongs to. Simplified input c...
Oldham asked 23/2, 2020 at 2:27

3

Solved

Is there a pythonic way to group by a field and check if all elements of each resulting group have the same value? Sample data: datetime rating signal 0 2018-12-27 11:33:00 IG 0 1 2018-12-27 11:33...
Triable asked 27/12, 2018 at 21:7

3

Solved

I want to improve the time of a groupby in python pandas. I have this code: df["Nbcontrats"] = df.groupby(['Client', 'Month'])['Contrat'].transform(len) The objective is to count how many contr...
Possie asked 1/7, 2016 at 11:0

2

Solved

I have a multi-index dataframe that shows the sum of transactions on a monthly frequency. I am trying to get a cumsum() on yearly basis that respects my 'mapid' and 'service' multi-index. However...
Sheathe asked 17/5, 2018 at 21:5

3

Solved

I have a situation where I need to print all the distinct values that are there for all the categorical columns in my data frame The dataframe looks like this : Gender Function Segment M IT LE F I...
Sempiternal asked 28/1, 2020 at 14:34

5

Solved

Is there a pandas built-in way to apply two different aggregating functions f1, f2 to the same column df["returns"], without having to call agg() multiple times? Example dataframe: import...
Shiflett asked 25/9, 2012 at 19:5

3

I need to group a DataFrame and apply several chained functions on each group. My problem is basically the same as in pandas - Groupby two functions: apply cumsum then shift on each group. There ar...
Tartlet asked 2/2, 2022 at 15:57

3

I have a dataframe news_count. Here are its column names, from the output of news_count.columns.values: [('date', '') ('EBIX UW Equity', 'NEWS_SENTIMENT_DAILY_AVG') ('Date', '') ('day', '') ('mo...
Forepleasure asked 2/10, 2017 at 22:31

4

Solved

I've heard in Pandas there's often multiple ways to do the same thing, but I was wondering – If I'm trying to group data by a value within a specific column and count the number of items with tha...
Betake asked 25/11, 2017 at 15:49

1

Solved

I want to include NA values when using groupby() which does not happen by default. I think the option dropna=False make it happen. But when the column is of type Categorical the option has no effec...
Autostability asked 2/11, 2021 at 12:58

6

Solved

I am having issues using pandas groupby with categorical data. Theoretically, it should be super efficient: you are grouping and indexing via integers rather than strings. But it insists that, when...
Posthaste asked 27/1, 2018 at 1:12

2

Solved

After updating to pandas v0.25.2 a script doing a groupby over many columns on a large dataframe no longer works. I get a memory error MemoryError: Unable to allocate array with shape (some huge nu...
Odious asked 6/1, 2020 at 18:49

3

Solved

I am processing a pandas dataframe df1 with prices of items. Item Price Minimum Most_Common_Price 0 Coffee 1 1 2 1 Coffee 2 1 2 2 Coffee 2 1 2 3 Tea 3 3 4 4 Tea 4 3 4 5 Tea 4 3 4 I create Minim...
Raylenerayless asked 20/12, 2017 at 4:25

2

Solved

I have the following dataframe: date id cars 2012 1 4 2013 1 6 2014 1 NaN 2012 2 10 2013 2 20 2014 2 NaN Now, I want to get the mean of cars over the years for each id ignoring the NaN's. T...
Melgar asked 31/5, 2017 at 12:33

4

Solved

Python newbie here. I'm trying to understand how the pandas groupby and apply methods work. I found this simple example, which I paste below: import pandas as pd ipl_data = {'Team': ['Riders', 'R...
Quinquagesima asked 1/9, 2019 at 16:56

4

Solved

I have a dataframe with an id column and a quantity column, which can be 0 or 1. import pandas as pd df = pd.DataFrame([ {'id': 'thing 1', 'date': '2016-01-01', 'quantity': 0 }, {'id': 'thing 1',...
Failing asked 11/2, 2021 at 15:20

4

Solved

I have a pandas dataframe that looks like this ID country month revenue profit ebit 234 USA 201409 10 5 3 344 USA 201409 9 7 2 532 UK 201410 20 10 5 129 Canada 201411 15 10 5 I want to group by ...
Cutshall asked 13/2, 2018 at 14:3

7

Want to output a Pandas groupby dataframe to CSV. Tried various StackOverflow solutions but they have not worked. Python 3.6.1, Pandas 0.20.1 groupby result looks like: id month year count wee...
Yahweh asked 1/12, 2017 at 22:2

4

Solved

Is there any way I can retain the original index of my large dataframe after I perform a groupby? The reason I need to this is because I need to do an inner merge back to my original df (after my g...
Stadiometer asked 11/3, 2018 at 3:31

4

Im trying to retrieve only the max values (including the multi index values) from a pandas dataframe that has multiple indexes. The dataframe I have is generated via a groupby and column selection ...
Ceporah asked 23/2, 2018 at 21:20

© 2022 - 2024 — McMap. All rights reserved.