data is not defined

parent 9771f7d0
...@@ -2074,53 +2074,58 @@ ...@@ -2074,53 +2074,58 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"def convert_week(year_and_week_int):\n",
" year_and_week_str = str(year_and_week_int)\n",
" year = int(year_and_week_str[:4])\n",
" week = int(year_and_week_str[4:])\n",
" w = isoweek.Week(year, week)\n",
" return pd.Period(w.day(0), 'W')"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'data' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-40-4170f9fe0be0>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'period'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mconvert_week\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0myw\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0myw\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'week'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'data' is not defined"
]
}
],
"source": [
"data['period'] = [convert_week(yw) for yw in data['week']]"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "ename": "NameError",
"output_type": "stream", "evalue": "name 'data' is not defined",
"text": [ "output_type": "error",
"1991 12615.384615384615\n", "traceback": [
"1992 15915.094339622641\n", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"1993 11412.211538461539\n", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"1994 12700.346153846154\n", "\u001b[0;32m<ipython-input-41-eb886c840e17>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msorted_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'period'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"1995 12588.423076923076\n", "\u001b[0;31mNameError\u001b[0m: name 'data' is not defined"
"1996 12157.923076923076\n",
"1997 12005.807692307691\n",
"1998 14812.358490566037\n",
"1999 12423.5\n",
"2000 12434.942307692309\n",
"2001 10834.903846153846\n",
"2002 11337.442307692309\n",
"2003 13056.307692307691\n",
"2004 16052.169811320755\n",
"2005 12585.5\n",
"2006 10728.942307692309\n",
"2007 14963.826923076924\n",
"2008 14211.403846153846\n",
"2009 16527.11320754717\n",
"2010 14739.961538461539\n",
"2011 12346.807692307691\n",
"2012 13018.673076923076\n",
"2013 12659.961538461539\n",
"2014 12473.211538461539\n",
"2015 12259.283018867925\n",
"2016 14038.51923076923\n",
"2017 10703.461538461539\n",
"2018 10796.153846153846\n",
"2019 10401.423076923076\n",
"2020 4339.377358490566\n"
] ]
} }
], ],
"source": [ "source": [
"raw_data[\"year\"] = raw_data[\"week\"].astype(str).apply(lambda x: x[:4])\n", "sorted_data = data.set_index('period').sort_index()"
"raw_data[\"year\"] = raw_data[\"year\"].astype(int)\n",
"\n",
"for year in range(1991, 2021):\n",
" print(year, raw_data[raw_data[\"year\"] == year][\"inc\"].mean())\n",
"\n"
] ]
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment