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

Select Multiple Columns #1

Closed
patrizok opened this issue Sep 19, 2022 · 2 comments
Closed

Select Multiple Columns #1

patrizok opened this issue Sep 19, 2022 · 2 comments

Comments

@patrizok
Copy link

Hello,

First of all, thanks for writing this Linque library. This is the best linq alternative for python.

I want to select multiple columns;
This works for one column:
Linque(mydict).select(lambda d: d['phones']).flatten(lambda d: d)

But I need something like;
Linque(mydict).select(lambda d: d['phones'] or d['mobilephones']).flatten(lambda d: d)

Is this possible? If not can yolu please develop this feature?

@xxao
Copy link
Owner

xxao commented Jan 1, 2023

Hi,
could you please provide more specific example with expected input and output?

@MartinStrohalm
Copy link
Contributor

Assuming the following data structure, this might be the way:

import linque

data = [
    {"col1": (1, 2, 3), "col2": (4, 5, 6), "col3": (7, 8, 9)},
    {"col1": (10, 20, 30), "col2": (40, 50, 60), "col3": (70, 80, 90)}]

linq = linque.Linque(data).select(lambda d: d["col1"] + d["col2"]).flatten().to_list()
print(linq)

# [1, 2, 3, 4, 5, 6, 10, 20, 30, 40, 50, 60]

Please note, that the data type of columns must be the same (e.g. both lists or both tuples) otherwise you cannot use the "+" to join them. If they are different, you would need to manually change it like:

linq = linque.Linque(data).select(lambda d: list(d["col1"]) + list(d["col2"])).flatten().to_list()

@xxao xxao closed this as completed Jan 5, 2023
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