Last active
March 6, 2019 02:59
-
-
Save lppier/5aacf0aaf310ce2ad1e5f24bb3db321b to your computer and use it in GitHub Desktop.
Avoiding pandas copywithsetting error
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
#SettingWithCopyWarning: | |
#A value is trying to be set on a copy of a slice from a DataFrame. | |
#Try using .loc[row_indexer,col_indexer] = value instead | |
# assign was introduced in pandas 0.16 to deal with this false positive | |
# Instead of | |
df_weekly_season.loc[:, 'market'] = market | |
# or | |
df_weekly_season['market'] = market | |
# do | |
df_weekly_season = df_weekly_season.assign(market=market) | |
# Instead of | |
df_weekly_season['DOW_ENG'] = weekly_season['ds'].apply( | |
lambda x: calendar.day_name[pd.to_datetime(x).weekday()]) | |
# do | |
df_weekly_season = df_weekly_season.assign(DOW_ENG=weekly_season['ds'].apply( | |
lambda x: calendar.day_name[pd.to_datetime(x).weekday()])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment