python-polars Questions
5
I went through the entire documentation of Polars but couldn't find anything which could convert nested json into dataframe.
test = {
"name": "Ravi",
"Subjects": {
...
Colpin asked 21/11, 2021 at 4:10
2
Solved
I am trying to find a simple way of randomly splitting a polars dataframe in train and test. This is how I am doing it right now
train, test = df
.with_columns(pl.lit(np.random.rand(df0.height)>...
Orangy asked 9/6, 2023 at 19:15
4
Solved
I have a dataframe with 2 columns, where first column contains lists, and second column integer indexes.
How to get elements from first column by index specified in second column? Or even better, p...
Worden asked 26/10, 2022 at 5:2
2
Solved
I am trying to add a column of empty lists to a polars dataframe in python.
My code
import polars as pl
a = pl.DataFrame({'a': [1, 2, 3]})
a.with_columns([pl.lit([]).alias('b')])
throws
Traceback ...
Son asked 16/9, 2022 at 10:28
3
Solved
Is there a polars native way to explode out a column of lists horizontally?
e.g. go from this:
df = pl.DataFrame(
{
"letters": ["a", "a", "b", "c"...
Comate asked 7/11, 2023 at 19:16
3
Solved
I'm trying to display the full width of column in polars dataframe. Given the following polars dataframe:
import polars as pl
df = pl.DataFrame({
'column_1': ['TF-IDF embeddings are done on the ...
Eppes asked 4/4, 2023 at 13:3
2
Solved
How to add new feature like length of data frame & Drop rows value using indexing.
I want to a add a new column where I can count the no-of rows available in a data frame,
& using indexing ...
Former asked 15/3, 2022 at 16:50
1
I have a polars dataframe of species, 89 date columns and 23 unique species. The goal is aggregation by a groupby as well as a range of columns. iloc would be the way to do this in pandas, but the ...
Krafftebing asked 11/4, 2023 at 16:40
2
Solved
Being a new user to polars coming from pandas, I have searched polars GitHub pages, user guide, stackoverflow and discord channel on how to add a new column to a polars dataframe.
I have only found...
Misericord asked 13/3, 2023 at 9:26
3
Solved
I am trying to loop through a Polars recordset using the following code:
import polars as pl
df = pl.DataFrame({
"start_date": ["2020-01-02", "2020-01-03", "202...
Staggs asked 2/2, 2023 at 13:15
3
I created an empty dataframe with a set schema. The schema sets the columns data types. I want to add a single name-matching column (series) to the empty dataframe. But it seems to not like it.
# E...
Chesney asked 30/3, 2023 at 8:13
2
Solved
I wish to select only columns with fewer than 3 unique values. I can generate a boolean mask via pl.all().n_unique() < 3, but I don't know if I can use that mask via the polars API for this.
Cur...
Glenglencoe asked 22/8, 2022 at 15:4
3
Solved
Given the following dataframe, is there some way to select only columns starting with a given prefix? I know I could do e.g. pl.col(column) for column in df.columns if column.startswith("prefi...
Ovida asked 9/7, 2022 at 9:10
5
Solved
In Pandas we can use the map function to map a dict to a series to create another series with the mapped values. More generally speaking, I believe it invokes the index operator of the argument, i....
Unlawful asked 13/12, 2022 at 3:24
6
Solved
In pandas, the following code will split the string from col1 into many columns. is there a way to do this in polars?
d = {"col1": ["a/b/c/d", "a/b/c/d"]}
df= pd.DataF...
Twoseater asked 13/9, 2022 at 8:4
1
I want to write a Python extension using Rust with Ctypes or Pyo3 to get better performance than native Python. But how to exchange data such as Polars DataFrame or ndarray type between Rust and Py...
Winfrid asked 16/3, 2022 at 11:47
2
Solved
I have the following list of 20 values:
values = [143.15,143.1,143.06,143.01,143.03,143.09,143.14,143.18,143.2,143.2,143.2,143.31,143.38,143.35,143.34,143.25,143.33,143.3,143.33,143.36]
In order t...
Plebs asked 22/9, 2023 at 18:56
1
Please note, this is related to Exponential Moving Average (EMA) calculations in Polars dataframe that I raised 7 months ago.
Suppose I have the following values:
values = [143.15,143.1,143.06,143....
Deterrent asked 20/4, 2024 at 18:26
5
Solved
I am working with multiple parquet datasets that were written with nested structs (sometimes multiple levels deep). I need to output a flattened (no struct) schema. Right now the only way I can thi...
Fran asked 1/12, 2022 at 8:10
3
Given this dataframe:
df = pl.DataFrame({"s": ["pear", None, "papaya", "dragonfruit"]})
I want to remove the last X chars, e.g. remove the last 2 chars
from...
Eating asked 16/6, 2023 at 13:25
6
Background: I want to read some data from a text file, into a polars dataframe. The data starts at the line containing the string foo, and stops at the first empty line afterwards. Example file tes...
Related asked 20/3, 2024 at 22:53
2
Solved
What's the alternative of pandas :
data['ColumnA'].str[:2]
in python polars?
pl.col('ColumnA').str[:3]
throws TypeError: 'ExprStringNameSpace' object is not subscriptable
error.
Holotype asked 9/5, 2023 at 8:36
3
Solved
I'm looking for a function along the lines of
df.groupby('column').agg(sample(10))
so that I can take ten or so randomly-selected elements from each group.
This is specifically so I can read in a ...
Jezebel asked 15/6, 2022 at 14:45
3
Solved
I have a Polars DataFrame containing a column with strings representing 'sparse' sector exposures, like this:
df = pl.DataFrame(
pl.Series("sector_exposure", [
"Technology=0.207;Fi...
Sewan asked 9/4, 2024 at 20:25
2
Solved
I have scrubbed the polars docs and cannot see an example of creating a column with a fixed value from a variable. Here is what works in pandas:
df['VERSION'] = version
Thx
Zooid asked 3/3, 2022 at 16:10
© 2022 - 2025 — McMap. All rights reserved.