4
data = {"a": [1, 2], "b": [3, 4]}
df = pl.DataFrame(data)

print(df['a'].to_numpy()
[1 2]

print(df.select('a').to_numpy())
[[1][2]]

On the one hand it's adwised to not use the df['some_column'] syntax, but on the other hand they yield different results.

Is there a way with polars to say df.select('some_column').values like in pandas?

supersick
  • 261
  • 2
  • 14

1 Answers1

4

You can use the get_column function. This returns a Series. (select returns a DataFrame.)

df.get_column('a').to_numpy()
array([1, 2])
>>> type(df.get_column('a').to_numpy())
<class 'numpy.ndarray'>