Transformação de Dados com Polars
Liam Brannigan
Data Scientist & Polars Contributor
shape: (5, 5)
| business | location | type | rating | capacity |
| --- | --- | --- | --- | --- |
| str | str | str | i64 | i64 |
|------------------|-----------------|------------|--------|----------|
| 7burgers | Wakey Wakey | restaurant | 5 | 55 |
| Bang Bang Burger | Forest Rd. | restaurant | 4 | 55 |
| Costa Coffee | City Point | café | 5 | 41 |
| Costa Coffee | The Moorgate | takeaway | 3 | 0 |
| The Queens Head | Denman St. | bar | 5 | 187 |
ratings.with_columns(
)
ratings.with_columns(
pl.when( )
)
ratings.with_columns(
pl.when(pl.col("rating") == 5)
)
ratings.with_columns(
pl.when(pl.col("rating") == 5).then(pl.lit("Muito bem avaliado"))
)
$$
$$
pl.lit() para passar um valor literal, não um nome de colunaratings.with_columns(
pl.when(pl.col("rating") == 5).then(pl.lit("Muito bem avaliado"))
.otherwise(pl.lit("Precisa melhorar"))
)
ratings.with_columns(
pl.when(pl.col("rating") == 5).then(pl.lit("Muito bem avaliado"))
.otherwise(pl.lit("Precisa melhorar")).alias("quality")
)
ratings.with_columns(
pl.when(pl.col("rating") == 5).then(pl.lit("Muito bem avaliado"))
.otherwise(pl.lit("Precisa melhorar")).alias("quality")
)
shape: (5, 6)
| business | location | type | rating | capacity | quality |
| --- | --- | --- | --- | --- | --- |
| str | str | str | i64 | i64 | str |
|------------------|-----------------|------------|--------|----------|--------------------|
| 7burgers | Wakey Wakey | restaurant | 5 | 55 | Muito bem avaliado |
| Bang Bang Burger | Forest Rd. | restaurant | 4 | 55 | Precisa melhorar |
| ... | ... | ... | ... | ... | ... |
shape: (5, 5)
| business | location | type | rating | capacity |
| --- | --- | --- | --- | --- |
| str | str | str | i64 | i64 |
|------------------|-----------------|------------|--------|----------|
| 7burgers | Wakey Wakey | restaurant | 5 | 55 |
| Bang Bang Burger | Forest Rd. | restaurant | 4 | 55 |
| Costa Coffee | City Point | café | 5 | 41 |
| Costa Coffee | The Moorgate | takeaway | 3 | 0 |
| The Queens Head | Denman St. | bar | 5 | 187 |
ratings.with_columns(
)
ratings.with_columns(
pl.when(pl.col("capacity") > 100)
)
ratings.with_columns(
pl.when(pl.col("capacity") > 100).then(pl.lit("Grande"))
)
ratings.with_columns(
pl.when(pl.col("capacity") > 100).then(pl.lit("Grande"))
.when(pl.col("capacity") >= 20)
)
ratings.with_columns(
pl.when(pl.col("capacity") > 100).then(pl.lit("Grande"))
.when(pl.col("capacity") >= 20).then(pl.lit("Médio"))
)
ratings.with_columns(
pl.when(pl.col("capacity") > 100).then(pl.lit("Grande"))
.when(pl.col("capacity") >= 20).then(pl.lit("Médio"))
.otherwise(pl.lit("Pequeno"))
)
ratings.with_columns(
pl.when(pl.col("capacity") > 100).then(pl.lit("Grande"))
.when(pl.col("capacity") >= 20).then(pl.lit("Médio"))
.otherwise(pl.lit("Pequeno")).alias("venue_size")
)
shape: (3, 6)
| business | location | type | rating | capacity | venue_size |
| --- | --- | --- | --- | --- | --- |
| str | str | str | i64 | i64 | str |
|------------------|-----------------|------------|--------|----------|------------|
| 7burgers | Wakey Wakey | restaurant | 5 | 55 | Médio |
| Costa Coffee | The Moorgate | takeaway | 3 | 0 | Pequeno |
| The Queens Head | Denman St. | bar | 5 | 187 | Grande |
shape: (5, 5)
| business | location | type | rating | capacity |
| --- | --- | --- | --- | --- |
| str | str | str | i64 | i64 |
|------------------|-----------------|------------|--------|----------|
| 7burgers | Wakey Wakey | restaurant | 5 | 55 |
| Bang Bang Burger | Forest Rd. | restaurant | 4 | 55 |
| Costa Coffee | City Point | café | 5 | 41 |
| Costa Coffee | The Moorgate | takeaway | 3 | 0 |
| The Queens Head | Denman St. | bar | 5 | 187 |
typeratings.with_columns(
pl.col("type")
)
ratings.with_columns(
pl.col("type").replace( )
)
ratings.with_columns(
pl.col("type").replace("café", "restaurant")
)
shape: (5, 5)
| business | location | type | rating | capacity |
| --- | --- | --- | --- | --- |
| str | str | str | i64 | i64 |
|------------------|-----------------|------------|--------|----------|
| 7burgers | Wakey Wakey | restaurant | 5 | 55 |
| Bang Bang Burger | Forest Rd. | restaurant | 4 | 55 |
| Costa Coffee | City Point | restaurant | 5 | 41 |
| Costa Coffee | The Moorgate | takeaway | 3 | 0 |
| The Queens Head | Denman St. | bar | 5 | 187 |
Transformação de Dados com Polars