Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression error in 02-Working-With-Data/07-python/notebook.ipynb #545

Open
aniveshkanodia opened this issue Apr 12, 2024 · 1 comment
Open

Comments

@aniveshkanodia
Copy link

aniveshkanodia commented Apr 12, 2024

Describe the bug
Code to demonstrate the concept of grouping in pandas errors out because it tries to perform .mean() to text column B

I believe it should be - df.groupby(by='LenB')[['A','DivA']].mean()

@Vednawale
Copy link

import pandas as pd

Sample DataFrame

data = {
'LenB': ['short', 'long', 'short', 'long'],
'A': [1, 2, 3, 4],
'DivA': [10, 20, 30, 40],
'B': ['text1', 'text2', 'text3', 'text4'] # Non-numeric column
}

df = pd.DataFrame(data)

Group by 'LenB' and calculate mean of only numeric columns

result = df.groupby(by='LenB')[['A', 'DivA']].mean()
print(result)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@aniveshkanodia @Vednawale and others