How to make dummy variables from four seasons in python? For example, so that when summer it takes the value 0, etc.

data=pd.read_csv('FF_monthly_anova_AU.csv', parse_dates=True, dayfirst=True, index_col=[0]) data['season']='summer' data.ix[(data.index.month>=3)&(data.index.month<=5),'season']='autumn' data.ix[(data.index.month>=6)&(data.index.month<=8),'season']='winter' data.ix[(data.index.month>=9)&(data.index.month<=11),'season']='spring' 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

I think it's worth looking at this example :

 import pandas as pd s = pd.Series(list('abca')) pd.get_dummies(s) abc 0 1 0 0 1 0 1 0 2 0 0 1 3 1 0 0 
     seasons = ['зима', 'весна', 'лето', 'осень'] def getseason(month_num): return seasons[int((month_num + 1)/3)%4] for item in range(12): print(str(item+1) + ': ' + getseason(item)) 

    PS: I hope the essence is true