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", "2020-01-04"],
"Name": ["John", "Joe", "James"]
})
for row in df.rows():
print(row)
('2020-01-02', 'John')
('2020-01-03', 'Joe')
('2020-01-04', 'James')
Is there a way to specifically reference 'Name' using the named column as opposed to the index? In Pandas this would look something like:
import pandas as pd
df = pd.DataFrame({
"start_date": ["2020-01-02", "2020-01-03", "2020-01-04"],
"Name": ["John", "Joe", "James"]
})
for index, row in df.iterrows():
df['Name'][index]
'John'
'Joe'
'James'
for row in mydf.iterrows(named=True): row['Name']
, I get the errorTraceback (most recent call last): File "<stdin>", line 2, in <module> TypeError: tuple indices must be integers or slices, not str
– Staggs