python-polars

How to mention custom daterange using polars Dataframe in python plotly plots?

How to mention custom daterange using polars Dataframe in python plotly plots? Question: I am new to python polars and trying to create a line plot using plotly express with custom start date & max date as the x-axis date range of the plot. Doubt: Do I need to pass the whole polars dataframe again …

Total answers: 1

How to fill a polars dataframe from a numpy array in python

How to fill a polars dataframe from a numpy array in python Question: I am currently working on a dataframe function that assigns values of a numpy array of shape 2 to a given column of a dataframe using the polars library in Python. I have a dataframe df with the following columns : [‘HZ’, …

Total answers: 1

Apply name-entity recognition on specific dataframe columns with Polars

Apply name-entity recognition on specific dataframe columns with Polars Question: I would like to apply a specific function to specific columns using polars similar to the following question: Apply name-entity recognition on specific dataframe columns Above question works with pandas and it is taking ages for me to run it on my computer. So, I …

Total answers: 3

Polars Python not converting to Datetime format when parsing

Polars Python not converting to Datetime format when parsing Question: Like the title says, I don’t know why it’s not converting to datetime. df = pl.read_csv(file, ignore_errors=True, parse_dates=True) df.columns = list(map(lambda x: x.replace(‘ ‘, ”), df.columns)) df_new = df.select(pl.col([‘Date_Convert’,’Region’])) print(df_new.head()) shape: (5, 2) enter image description here I tried doing it without parsing on load. …

Total answers: 2

Numpy array to list of lists in polars dataframe

Numpy array to list of lists in polars dataframe Question: I’m trying to save a dataframe with a 2D list in each cell to a parquet file. As example I created a polars dataframe with a 2D list. As can be seen in the table the dtype of both columns is list[list[i64]]. ┌─────────────────────┬─────────────────────┐ │ a …

Total answers: 1

Polars for Python: How to get rid of "Ensure you pass a path to the file instead of a python file object" warning when reading to a dataframe?

Polars for Python: How to get rid of "Ensure you pass a path to the file instead of a python file object" warning when reading to a dataframe? Question: The statement I’m reading data sets using Polars.read_csv() method via a Python file handler: with gzip.open(os.path.join(getParameters()[‘rdir’], dataset)) as compressed_file: df = pl.read_csv(compressed_file, sep = ‘t’, ignore_errors=True) …

Total answers: 1

Trouble with strptime() conversion of duration time string

Trouble with strptime() conversion of duration time string Question: I have some duration type data (lap times) as pl.Utf8 that fails to convert using strptime, whereas regular datetimes work as expected. Minutes (before 🙂 and Seconds (before .) are always padded to two digits, Milliseconds are always 3 digits. Lap times are always < 2 …

Total answers: 3

Polars Row object to Dictionary

Polars Row object to Dictionary Question: I’m trying to iterate through the rows of a Polars DataFrame, where the iterator returns a dictionary of each row. The documentation indicates that iter_rows(named=True) is what I want. However, I get an "AttributeError: ‘DataFrame’ object has no attribute ‘iter_rows’" error when I try to use it. iterrows(named=True) without …

Total answers: 1

Python Polars group by on both time and categorical values

Python Polars group by on both time and categorical values Question: There is a polars dataframe which consists of 3 fields listed below. user_id date part_of_day i32 datetime[ns] cat 173367 2021-08-03 00:00:00 "day" 132702 2021-10-28 00:00:00 "evening" 100853 2021-07-29 00:00:00 "night" 305810 2021-08-24 00:00:00 "day" 305239 2021-08-13 00:00:00 "day" My task is to calculate the …

Total answers: 1