Skip to content

How to implement pandas-style df.loc[] in Polars for custom library? #60093

@milisp

Description

@milisp

Polars issue

My goals

Create the ultimate bridge between the powerful performance of Polars and the intuitive, user-friendly API of Pandas.

My QA to chatgpt o1

Question

polars to pandas style, create a DataFrame, must use df.loc[], not df.loc()

df = DataFrame(
    {"ref": list('abcd'), 'x': [1,2,3,4], 'z': [7,8,9,6]},
    index=list('cfgh')
)

pass test

df.loc[df.ref == 'c']
df.loc[df.ref.eq('c')]
df.loc[(df.ref == 'c') & (df.x > 1)]
df.loc[(df.ref == 'c') | (df.x > 1)]
df.loc[df.ref.isin(['a','b'])]
df.loc[df.x.between(2,4)]
df.loc['c']
df.loc[:, 'x']
df.loc[:, ['x', 'z']]
df.loc[:, 'x':'z']
df.loc['c'][1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closing CandidateMay be closeable, needs more eyeballs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions