Code: Select all
result = df.select([col for idx, col in enumerate(df.columns) if idx != 1])
< /code>
Es sieht lang und ungeschickt für eine so einfache Aufgabe aus? < /p>
Ich habe es auch versucht: < /p>
df.select(pl.exclude(pl.nth(1)))
< /code>
Aber das fehlte < /p>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[20], line 1
----> 1 df.select(pl.exclude(pl.nth(1)))
File \.venv\Lib\site-packages\polars\functions\lazy.py:1855, in exclude(columns, *more_columns)
1785 def exclude(
1786 columns: str | PolarsDataType | Collection[str] | Collection[PolarsDataType],
1787 *more_columns: str | PolarsDataType,
1788 ) -> Expr:
1789 """
1790 Represent all columns except for the given columns.
1791
(...) 1853
1854 """
-> 1855 return F.col("*").exclude(columns, *more_columns)
File \.venv\Lib\site-packages\polars\expr\expr.py:851, in Expr.exclude(self, columns, *more_columns)
768 def exclude(
769 self,
770 columns: str | PolarsDataType | Collection[str] | Collection[PolarsDataType],
771 *more_columns: str | PolarsDataType,
772 ) -> Expr:
773 """
774 Exclude columns from a multi-column expression.
775
(...) 849 └──────┘
850 """
--> 851 return self.meta.as_selector().exclude(columns, *more_columns).as_expr()
File .venv\Lib\site-packages\polars\selectors.py:571, in Selector.exclude(self, columns, *more_columns)
566 else:
567 msg = (
568 "invalid input for `exclude`"
569 f"\n\nExpected one or more `str` or `DataType`; found {item!r} instead."
570 )
--> 571 raise TypeError(msg)
573 if exclude_cols and exclude_dtypes:
574 msg = "cannot exclude by both column name and dtype; use a selector instead"
TypeError: invalid input for `exclude`
Expected one or more `str` or `DataType`; found instead.