pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
26.9k stars 1.65k forks source link

Creating DataFrame from python list #16251

Open Vijendra07Kulhade opened 2 weeks ago

Vijendra07Kulhade commented 2 weeks ago

Checks

Reproducible example

import polars as pl
print(pl.__version__)

# Your 2D list
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

# Create DataFrame with column names
df = pl.DataFrame(data, columns=["A", "B", "C"])

print(df)

Log output

0.20.2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-4089a37271bc> in <cell line: 8>()
      6 
      7 # Create DataFrame with column names
----> 8 df = pl.DataFrame(data, columns=["A", "B", "C"])
      9 
     10 print(df)

TypeError: DataFrame.__init__() got an unexpected keyword argument 'columns'

Issue description

Unable to create DataFrame like Pandas.

Expected behavior

It should create dataframe like pandas.

Installed versions

``` Replace this line with the output of pl.show_versions(). Leave the backticks in place. ``` -------Version info--------- Polars: 0.20.2 Index type: UInt32 Platform: Linux-6.1.58+-x86_64-with-glibc2.35 Python: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] ----Optional dependencies---- adbc_driver_manager: 0.11.0 cloudpickle: 2.2.1 connectorx: 0.3.3 deltalake: 0.17.4 fsspec: 2023.6.0 gevent: 24.2.1 matplotlib: 3.7.1 numpy: 1.25.2 openpyxl: 3.1.2 pandas: 2.0.3 pyarrow: 14.0.2 pydantic: 2.7.1 pyiceberg: 0.6.1 pyxlsb: sqlalchemy: 2.0.30 xlsx2csv: 0.8.2 xlsxwriter: 3.2.0 None --------------------------------------------------------------------------- TypeError Traceback (most recent call last) [](https://localhost:8080/#) in () 6 7 # Create DataFrame with column names ----> 8 df = pl.DataFrame(data, columns=["A", "B", "C"]) 9 10 print(df) TypeError: DataFrame.__init__() got an unexpected keyword argument 'columns'
cmdlineluser commented 2 weeks ago

It's schema= in Polars.

>>> pl.DataFrame(data, schema=["A", "B", "C"])
shape: (3, 3)
┌─────┬─────┬─────┐
│ A   ┆ B   ┆ C   │
│ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╡
│ 1   ┆ 4   ┆ 7   │
│ 2   ┆ 5   ┆ 8   │
│ 3   ┆ 6   ┆ 9   │
└─────┴─────┴─────┘