Converting streams to billions
You are a data analyst at a record company. You have a Spotify dataset containing 25 popular albums with streaming metrics such as total plays, monthly listeners, and popularity scores. The streams column shows total plays as large integers that are hard to read, so you need to convert them to billions using a custom Python function.
polars is loaded as pl. The DataFrame spotify and a to_billions() function are preloaded for you.
本练习是课程的一部分
Data Transformation with Polars
练习说明
- Apply
to_billionsto thestreamscolumn to create a new column calledstreams_billions. - Specify the return type as
pl.Float64for explicit type control.
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Apply to_billions to the streams column
result = spotify.with_columns(
pl.col("streams").____(
____, return_dtype=____
).alias("streams_billions")
)
print(result.head())