-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop.py
38 lines (26 loc) · 835 Bytes
/
drop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Authors: Thierry Moudiki
#
# License: BSD 3
import pandas as pd
import polars as pl
from ..utils import polars_to_pandas, pandas_to_polars
# creates a copy
def drop(df, req=None):
""" Drop columns.
Args:
req: str
comma-separated list of columns to be dropped
Examples:
https://github.com/thierrymoudiki/querier/tree/master/querier/demo
"""
try:
if isinstance(df, pl.DataFrame):
df = polars_to_pandas(df)
result = df.drop(req.replace(" ", "").split(","), axis=1)
if isinstance(df, pl.DataFrame):
return pandas_to_polars(result)
return result
except:
raise ValueError(
"request must contain df" "s column names (comma-separated)"
)