Modern Polars: A comparison of the Polars and Pandas dataframe libraries
Does anyone else find the Polars syntax kind of clunky and ambiguous?<p>For example, from the link, here&#x27;s how Polars and Pandas handles manipulating data in a subset of a dataframe:<p><pre><code>  f = pl.DataFrame({&#x27;a&#x27;: [1,2,3,4,5], &#x27;b&#x27;:[10,20,30,40,50]})
  # Polars
  f.with_column(
      pl.when(pl.col(&quot;a&quot;) &lt;= 3)
      .then(pl.col(&quot;b&quot;) &#x2F;&#x2F; 10)
      .otherwise(pl.col(&quot;b&quot;))
  )
  # Pandas
  f.loc[f[&#x27;a&#x27;] &lt;= 3, &quot;b&quot;] = f[&#x27;b&#x27;] &#x2F;&#x2F; 10
</code></pre>
Its not clear in the Polars approach that the column &quot;b&quot; is being modified. An additional minor nitpick here is the use of when&#x2F;then&#x2F;otherwise for their conditional logic. Aren&#x27;t these just if&#x2F;else-if&#x2F;else conditions? It&#x27;s seems more in line with mathematical&#x2F;python convention to use if&#x2F;else... am I missing something?<p>The Pandas equivalent, on the other hand, is much more concise, and more explicit. It also seems more mathematical to me. Polars mutates the dataframe, whereas in Pandas a function is applied to a dataframe indexed like a matrix. Pandas also benefits from it&#x27;s reliance on symbolic notation, it makes everything visually clearer, whereas in Polars, the use of pl.col(&quot;b&quot;) and other similar methods contribute to multiple nested brackets and redundant naming calls contributing to less interpretability.<p>I know there&#x27;s a lot of thought thats been put into Polars, so I assume I&#x27;m missing some of the advantages of the Polars approach, and would appreciate anyone who can shed some light on it.<p>I do understand, and partially agree, with the idea that indexing in Pandas leads to a lot of bugs. But in the example above, Pandas isn&#x27;t really using indexing, it&#x27;s using a boolean map to &quot;index&quot; the values from the same dataframe, so should be fairly robust. Is there a reason why Polars is trying to avoid this kind of filtering in the row&#x2F;column indices?