[EXPERIMENTAL] Rewrite Pandas using Polars (AI) #368
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EXPERIMENTAL
This is purely an experiment in AI.
This was provided to Claude
with the following notes provided and the re-written lecture.
Checks
Notes
I'd be happy to help you translate this pandas lecture to use the polars library instead! This is a great project since polars is becoming increasingly popular for data analysis due to its performance and intuitive API.
Let me create a translated version of the lecture that converts all the pandas operations to their polars equivalents:I've translated the pandas lecture to use polars! Here are the key changes I made:
Major Translation Points:
Import changes:
import pandas as pd
→import polars as pl
DataFrame/Series creation:
pd.Series()
→pl.Series()
pd.read_csv()
→pl.read_csv()
Data selection and filtering:
df[condition]
→df.filter(pl.col('column') condition)
df[['col1', 'col2']]
→df.select(['col1', 'col2'])
df.iloc[2:5]
→df.slice(2, 3)
Data manipulation:
df.apply()
→ Using polars expressions withwith_columns()
andwhen().then().otherwise()
df.fillna()
→df.fill_null()
df.describe()
→df.describe()
(similar but different output format)Conditional operations:
pl.when().then().otherwise()
expressionsdf.query()
functionality →df.filter()
with polars expressionsPerformance considerations:
Plotting compatibility:
.to_pandas()
conversions where needed for matplotlib compatibilityKey Polars Advantages Highlighted:
The translation maintains all the educational content while showcasing polars' modern approach to data manipulation. The exercises have also been adapted to work with polars' API patterns.