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

enh: create dataframe from 2D numpy array and column names #1434

Open
MarcoGorelli opened this issue Nov 23, 2024 · 2 comments
Open

enh: create dataframe from 2D numpy array and column names #1434

MarcoGorelli opened this issue Nov 23, 2024 · 2 comments
Labels
enhancement New feature or request Medium priority

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Nov 23, 2024

For classical numpy dtypes in pandas, this should be more efficient than forcing slices + dicts

Spotted in Prophet

Desired syntax:

import narwhals as nw
import numpy as np
import pandas as pd

arr = np.zeros([[1,2,3], [4,5,6]])
df = nw.from_2d_array(arr, column_names=['a', 'b', 'c'])

It should also be possible to pass in dtype as an argument - if not passed, it'll be autoinferred

import narwhals as nw
import numpy as np
import pandas as pd

arr = np.zeros([[1,2,3], [4,5,6]])
df = nw.from_2d_array(arr, column_names=['a', 'b', 'c'], dtype=nw.Float64)
@MarcoGorelli MarcoGorelli added enhancement New feature or request Medium priority labels Nov 23, 2024
@FBruzzesi
Copy link
Member

Should this emulate polars.from_numpy with the extra namespace argument?

@MarcoGorelli
Copy link
Member Author

yup good shout!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Medium priority
Projects
None yet
Development

No branches or pull requests

2 participants