Last active
July 31, 2022 20:35
-
-
Save briandk/26f9efa7b82fa57367dda0ed1cead3a7 to your computer and use it in GitHub Desktop.
- Applying `pd.to_datetime()` to a column using `mutate` seems to fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from siuba import * | |
my_data = { | |
'name': ["Abigail Adams"], | |
'birth': ["1744-11-22"], | |
'death': ["1818-10-28"] | |
} | |
df = pd.DataFrame(my_data) | |
# This pipeline will raise an error: | |
# TypeError: Symbolic objects can not be converted to True/False, or used with these keywords: not, and, or. | |
( | |
df | |
>> mutate(birth_dt = pd.to_datetime(_.birth)) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from siuba import filter | |
from siuba import _ | |
my_data = pd.DataFrame({ | |
'dates': ["1776-07-04", pd.NA] | |
}) | |
# The pipeline below gives "TypeError: Cannot perform 'rand_' with a dtyped [object] array and scalar of type [bool]" | |
( | |
my_data | |
>> filter(_.dates) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plotnine.data import mpg | |
from siuba import rename | |
# This fails with an "invalid syntax" error | |
model = ( | |
mpg | |
>> rename(car_class = _.class) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from siuba import * | |
my_data = pd.DataFrame({ | |
"pop": [1, 2, 3] | |
}) | |
( | |
my_data | |
>> mutate(pop_doubled = _.pop * 2) | |
) # TypeError: unsupported operand type(s) for *: 'method' and 'int' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.formula.api as smf | |
from plotnine.data import mpg | |
# You'll get a syntax error, and I think it's because `class` | |
# is a reserved keyword in Python, even though it's also | |
# the name of a variable in the dataset. | |
model = smf.ols("cty ~ hwy + class", data=mpg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment