Skip to content

Issue on page /workflow-style.html #31

Description

@crossxwill

I suggest adding this example to "6.4. Line width and line continuation". Method chaining is easier to read inside parentheses and one line per method.

import pandas as pd
import numpy as np

df = pd.DataFrame(
    data={
        "col0": [0, 0, 0, 0],
        "col1": [0, 0, 0, 0],
        "col2": [0, 0, 0, 0],
        "col3": ["a", "b", "b", "a"],
        "col4": ["alpha", "gamma", "gamma", "gamma"],
    },
    index=["row" + str(i) for i in range(4)],
)

  
# Chaining inside parentheses works

results = (df
    .groupby(["col3", "col4"])
    .agg({"col1": "count", "col2": "mean"})
)

print(results)

# Error: SyntaxError: invalid syntax

results = df
    .groupby(["col3", "col4"])
    .agg({"col1": "count", "col2": "mean"})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions