pandas-groupby Questions
4
Solved
I have simple code to export python dataframe to existing excel file with sheets
but the writer keep deleting the existing sheet from the file
read = pd.ExcelFile('Saw_Load.xlsx')
print(read.shee...
Pivot asked 18/10, 2018 at 15:47
2
Solved
Lets say this is my data-frame
df = pd.DataFrame({ 'bio' : ['1', '1', '1', '4'],
'center' : ['one', 'one', 'two', 'three'],
'outcome' : ['f','t','f','f'] })
It looks like this ...
bio center...
Marin asked 4/8, 2017 at 3:32
2
In Pandas it is possible to tell how you want to aggregate your data by passing a string alias ('min' in the following example). From the docs, you have:
df.groupby('A').agg('min')
It is obvious w...
Fiction asked 25/1, 2021 at 0:42
1
I was performing a simple example of financial data, trying to make a classic candlestick plot. To do it I had to calculate Open, Max, Min and Close for each unit of time. I decided to use the resa...
Cowherb asked 21/3, 2020 at 14:18
5
Solved
How to get last 'n' groups after df.groupby() and combine them as a dataframe.
data = pd.read_sql_query(sql=sqlstr, con=sql_conn, index_col='SampleTime')
grouped = data.groupby(data.index.date,so...
Grandma asked 19/10, 2018 at 15:14
3
Solved
I have labeled event (time series) data where the events occur at random intervals for a given label. I would like to compute the within group ewma and add it to the dataframe as a new column "X1_E...
Swanson asked 19/9, 2019 at 1:53
5
I have sample snippet that works as expected:
import pandas as pd
df = pd.DataFrame(data={'label': ['a', 'b', 'b', 'c'], 'wave': [1, 2, 3, 4], 'y': [0,0,0,0]})
df['new'] = df.groupby(['label'])[[...
Allout asked 1/9, 2019 at 6:47
3
Solved
Summary:
I have many columns with data (data_cols) and with text (text_cols), I'd like to do the following by referring to a list of column names, but cannot figure it out:
df.groupby('id', as_inde...
Lavernlaverna asked 27/5, 2021 at 7:22
2
Solved
I have a pandas data frame with a column 'id' and a column 'value'. It is already sorted by first id (ascending) and then value (descending). What I need is the top 10 values per id.
I assumed th...
Hague asked 16/10, 2015 at 10:36
5
I am having the following python/pandas command:
df.groupby('Column_Name').agg(lambda x: x.value_counts().max()
where I am getting the value counts for ALL columns in a DataFrameGroupBy object.
...
Pralltriller asked 27/6, 2018 at 13:8
3
Solved
If it's single row, I can get the iterator as following
import pandas as pd
import numpy as np
a = np.zeros((100,40))
X = pd.DataFrame(a)
for index, row in X.iterrows():
print index
print row
...
Mak asked 21/7, 2016 at 16:4
4
Solved
With Pandas groupby, I can do things like this:
>>> df = pd.DataFrame(
... {
... "A": ["foo", "bar", "bar", "foo", "bar"],
... ...
Conversational asked 2/2, 2022 at 15:12
3
When using seaborn, is there a way I can include multiple variables (columns) for the hue parameter? Another way to ask this question would be how can I group my data by multiple variables before p...
Apologize asked 23/2, 2020 at 20:10
3
Solved
My data set df looks as follows:
Date Value
...
2012-07-31 61.9443
2012-07-30 62.1551
2012-07-27 62.3328
... ...
2011-10-04 48.3923
2011-10-03 48.5939
2011-09-30 50.0327
2011-09-29 51.8350
2011-09...
Finnougrian asked 22/6, 2020 at 17:15
3
Solved
My dataframe looks like this:
SKU # GRP CATG PRD
0 54995 9404000 4040 99999
1 54999 9404000 4040 99999
2 55037 9404000 4040 1556894
3 55148 9404000 4040 1556894
4 55254 9404000 4040 1556894
5 55...
Saltish asked 17/2, 2020 at 20:39
2
Solved
I am trying to build a scalable method to calculate the number of unique members that have modified a certain file up to and including the latest modified_date. The unique_member_until_now column c...
Oden asked 26/12, 2021 at 18:55
2
Solved
Assuming i have the following data frame
date
flag
user
num
0
2019-01-01
1
a
10
1
2019-01-02
0
a
20
2
2019-01-03
1
b
30
3
2019-03-04
1
b
40
I want to create a cumulative sum of ...
Bounty asked 15/12, 2021 at 18:25
1
Solved
I have a dataframe with
5 millions of rows.
a column group_id whose number of unique elements is 500.000.
thousands of other columns named var1, var2, etc. Each of var1, var2, ... contains only 0 ...
Mithridatism asked 11/12, 2021 at 11:38
1
Solved
I have following dataframe in which I want to make a cumulative sum on a certain column (Value), together with a group by on field Group, but reset that cumulative sum to 0 when a value in another ...
Hayrick asked 9/12, 2021 at 18:49
2
Solved
Below is a sample data frame:
df = pd.DataFrame({'StudentName': ['Anil','Ramu','Ramu','Anil','Peter','Peter','Anil','Ramu','Peter','Anil'],
'ExamDate': ['2021-01-10','2021-01-20','2021-02-22','202...
Goop asked 18/11, 2021 at 17:20
3
Solved
I have a dataframe df which can be created with this:
data={'id':[1,1,1,1,2,2,2,2],
'date1':[datetime.date(2016,1,1),datetime.date(2016,1,2),datetime.date(2016,1,3),datetime.date(2016,1,4),
date...
Revanche asked 4/1, 2018 at 21:28
4
I have:
df = pd.DataFrame({'A':[1, 2, -3],'B':[1,2,6]})
df
A B
0 1 1
1 2 2
2 -3 6
Q: How do I get:
A
0 1
1 2
2 1.5
using groupby() and aggregate()?
Something like,
df.groupby([0,1], axis=...
Luculent asked 24/12, 2017 at 20:53
2
Solved
I need to groupby-transform a dataframe by a datetime column AND another str(object) column to apply a function by group and asign the result to each of the row members of the group. I understand t...
Overdraft asked 5/9, 2018 at 14:45
2
Solved
I'm facing an issue with grouping and transforming on non-NA values in my dataframe.
So my dataframe is something like this:
Name
Value
A
1
A
2
A
NaN
B
3
B
7
B
9
B
NaN
Final...
Stagy asked 6/9, 2021 at 11:6
2
Solved
The dataframe is an empty df after query.when groupby,raise runtime waring,then get another empty dataframe with no columns.How to keep the columns?
df = pd.DataFrame(columns=["PlatformCategory","...
Kermanshah asked 7/9, 2017 at 7:28
© 2022 - 2024 — McMap. All rights reserved.