import%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20app_title%3D%22Primer%3A%20pandas%202%20to%203%22)%0A%0Awith%20app.setup%3A%0A%20%20%20%20%23%20The%20setup%20cell%20runs%20first.%20It%20holds%20the%20imports%20and%20settings%20every%20other%20cell%20uses.%0A%20%20%20%20import%20io%0A%20%20%20%20import%20warnings%0A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%0A%20%20%20%20import%20course%20%20%23%20this%20course's%20helpers%3A%20file%20locations%20and%20the%20survey%20read%20the%20way%20the%20course%20teaches%0A%0A%20%20%20%20%23%20pandas'%20own%20pages%20this%20primer%20checks%20every%20change%20against%0A%20%20%20%20V30%20%3D%20%22https%3A%2F%2Fpandas.pydata.org%2Fdocs%2Fwhatsnew%2Fv3.0.0.html%22%0A%20%20%20%20V31%20%3D%20%22https%3A%2F%2Fpandas.pydata.org%2Fdocs%2Fwhatsnew%2Fv3.1.0.html%22%0A%20%20%20%20GUIDE%20%3D%20%22https%3A%2F%2Fpandas.pydata.org%2Fdocs%2Fuser_guide%2Fmigration.html%22%0A%0A%0A%40app.function%0Adef%20show(example)%20-%3E%20mo.Html%3A%0A%20%20%20%20%22%22%22Run%20a%20small%20example%20and%20show%20what%20happened%3A%20every%20warning%20it%20raised%20(the%20code%20ran)%2C%20then%20either%20what%20it%20gave%20back%0A%20%20%20%20or%20the%20error%20that%20stopped%20it.%22%22%22%0A%20%20%20%20with%20warnings.catch_warnings(record%3DTrue)%20as%20caught%3A%0A%20%20%20%20%20%20%20%20warnings.simplefilter(%22always%22)%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20result%2C%20error%20%3D%20example()%2C%20None%0A%20%20%20%20%20%20%20%20except%20Exception%20as%20exc%3A%20%20%23%20the%20error%20is%20the%20lesson%3A%20show%20it%20rather%20than%20stop%20the%20notebook%0A%20%20%20%20%20%20%20%20%20%20%20%20result%2C%20error%20%3D%20None%2C%20exc%0A%20%20%20%20parts%20%3D%20%5B%5D%0A%20%20%20%20for%20warning%20in%20caught%3A%0A%20%20%20%20%20%20%20%20first%20%3D%20str(warning.message).strip().splitlines()%5B0%5D%0A%20%20%20%20%20%20%20%20parts.append(mo.callout(mo.md(f%22**Warning%3A%20%7Bwarning.category.__name__%7D.**%20The%20code%20ran%2C%20but%20pandas%20says%3A%5Cn%5Cn%60%60%60text%5Cn%7Bfirst%7D%5Cn%60%60%60%22)%2C%20kind%3D%22warn%22))%0A%20%20%20%20if%20error%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20parts.append(mo.callout(mo.md(f%22**Error%3A%20%7Btype(error).__name__%7D.**%20The%20code%20stopped%20here%3A%5Cn%5Cn%60%60%60text%5Cn%7Bstr(error).strip().splitlines()%5B0%5D%20if%20str(error).strip()%20else%20type(error).__name__%7D%5Cn%60%60%60%22)%2C%20kind%3D%22danger%22))%0A%20%20%20%20elif%20isinstance(result%2C%20(pd.DataFrame%2C%20pd.Series))%3A%0A%20%20%20%20%20%20%20%20parts.append(result)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20parts.append(mo.md(f%22It%20gave%20back%3A%20%60%7Bresult!r%7D%60%22))%0A%20%20%20%20return%20mo.vstack(parts)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%20Primer%3A%20pandas%202%20to%203%0A%0A%20%20%20%20This%20course%20is%20taught%20in%20pandas%203.%20Most%20of%20what%20you%20will%20find%20elsewhere%2C%20in%20tutorials%2C%20answers%20on%20forums%2C%20colleagues'%20scripts%20and%20code%20written%20by%20AI%20assistants%2C%20was%20written%20for%20pandas%202.%20Most%20of%20it%20still%20works.%20This%20primer%20is%20the%20part%20that%20does%20not%3A%20every%20change%20from%20pandas%202%20to%20pandas%203%20that%20a%20learner%20of%20this%20course%20meets%2C%20in%20one%20place.%0A%0A%20%20%20%20This%20notebook%20is%20running%20**pandas%20%7Bpd.__version__%7D**.%0A%0A%20%20%20%20Each%20change%20has%20the%20same%20four%20lines%3A%0A%0A%20%20%20%20%7C%20line%20%7C%20what%20it%20says%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20what%20the%20old%20code%20did%20(pandas%202.3%2C%20the%20last%20minor%20version%20of%20pandas%202%2C%20run%20when%20this%20primer%20was%20written)%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20what%20it%20does%20now%2C%20shown%20live%20in%20the%20cell%20below%20it%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20the%20code%20to%20write%20instead%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20the%20section%20of%20pandas'%20own%20release%20notes%20that%20announces%20the%20change%20%7C%0A%0A%20%20%20%20The%20examples%20run%20on%20the%20farm%20survey%20where%20they%20can.%20A%20**warning**%20box%20means%20the%20code%20ran%20but%20pandas%20has%20something%20to%20say%3B%20an%20**error**%20box%20means%20it%20stopped.%20Read%20either%20from%20its%20first%20line%3A%20it%20names%20what%20happened.%0A%0A%20%20%20%20%7C%20part%20%7C%20the%20changes%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%201%20%C2%B7%20Copy-on-write%20%7C%20chained%20assignment%2C%20changing%20a%20selection%2C%20%60inplace%3D%60%20%7C%0A%20%20%20%20%7C%202%20%C2%B7%20Text%3A%20the%20%60str%60%20type%20%7C%20the%20new%20type%2C%20missing%20values%2C%20%60astype(str)%60%2C%20codes%20as%20categories%20%7C%0A%20%20%20%20%7C%203%20%C2%B7%20Dates%20and%20times%20%7C%20microseconds%2C%20%60%22ME%22%60%20for%20month%20end%2C%20%60pct_change%60%20and%20gaps%2C%20reading%20dates%20%7C%0A%20%20%20%20%7C%204%20%C2%B7%20Selecting%20and%20setting%20%7C%20%60s%5B0%5D%60%2C%20values%20of%20the%20wrong%20type%20%7C%0A%20%20%20%20%7C%205%20%C2%B7%20Grouping%20%7C%20categories%20with%20no%20rows%2C%20the%20grouping%20column%20in%20%60apply%60%2C%20%60value_counts%60%20%7C%0A%20%20%20%20%7C%206%20%C2%B7%20Missing%20values%20in%20nullable%20columns%20%7C%20%60NA%60%20from%20arithmetic%20%7C%0A%20%20%20%20%7C%207%20%C2%B7%20Removed%3A%20what%20to%20write%20instead%20%7C%20one%20table%20%7C%0A%20%20%20%20%7C%208%20%C2%B7%20New%20in%20pandas%203%2C%20worth%20knowing%20%7C%20%60pd.col%60%2C%20%60select%60%2C%20%60filter%60%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%201%20%C2%B7%20Copy-on-write%0A%0A%20%20%20%20In%20pandas%202%2C%20whether%20a%20selection%20(%60df%5B%22col%22%5D%60%2C%20%60df%5Bmask%5D%60%2C%20%60df.loc%5B...%5D%60)%20was%20a%20**view**%2C%20sharing%20its%20numbers%20with%20the%20table%20it%20came%20from%2C%20or%20a%20**copy**%2C%20having%20its%20own%2C%20depended%20on%20the%20exact%20operation.%20Change%20a%20view%20and%20the%20table%20changed%20too%3B%20change%20a%20copy%20and%20it%20did%20not.%20pandas%20could%20not%20always%20tell%20which%20you%20had%2C%20so%20it%20warned%2C%20with%20the%20%60SettingWithCopyWarning%60%20many%20people%20learned%20to%20silence%20with%20%60.copy()%60.%0A%0A%20%20%20%20pandas%203%20has%20one%20rule%2C%20called%20**copy-on-write**%3A%20*anything%20you%20get%20from%20a%20table%20behaves%20as%20a%20copy.*%20The%20only%20way%20to%20change%20a%20table%20is%20to%20change%20it%20directly%2C%20in%20one%20step.%20Under%20the%20hood%20pandas%20still%20shares%20numbers%20where%20it%20safely%20can%2C%20and%20copies%20only%20at%20the%20moment%20something%20is%20changed%3A%20hence%20the%20name.%20Module%203%20teaches%20it%20in%20%5Bsection%204%5D(%2F%3Ffile%3D20_dataframes.py).%0A%0A%20%20%20%20The%20example%20table%3A%20the%20first%20five%20plots%20of%20the%20survey.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20first_plots%20%3D%20course.plots().head(5)%5B%5B%22hh_id%22%2C%20%22plot_no%22%2C%20%22crop%22%2C%20%22area_ha%22%2C%20%22production_kg%22%5D%5D%0A%20%20%20%20first_plots%0A%20%20%20%20return%20(first_plots%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%201.1%20%C2%B7%20Chained%20assignment%20never%20changes%20the%20table%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60df%5B%22col%22%5D%5Bmask%5D%20%3D%20value%60%20(two%20steps%20of%20%60%5B...%5D%60%20on%20the%20left%20of%20%60%3D%60%2C%20called%20**chained%20assignment**)%20usually%20changed%20%60df%60%2C%20with%20a%20%60SettingWithCopyWarning%60%3B%20pandas%202.3%20also%20warned%20it%20would%20stop%20working.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20It%20never%20changes%20%60df%60.%20pandas%20warns%20with%20%60ChainedAssignmentError%60%2C%20and%20the%20table%20stays%20as%20it%20was.%20%60SettingWithCopyWarning%60%20no%20longer%20exists.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20%60df.loc%5Bmask%2C%20%22col%22%5D%20%3D%20value%60%3A%20one%20step%2C%20on%20the%20table%20itself.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Consistent%20copy%2Fview%20behaviour%20with%20Copy-on-Write%5D(%7BV30%7D%23consistent-copy-view-behaviour-with-copy-on-write)%20%C2%B7%20%5Bmigration%20guide%3A%20Chained%20assignment%5D(%7BGUIDE%7D%23chained-assignment)%20%C2%B7%20%5B3.1%3A%20Other%20deprecations%5D(%7BV31%7D%23other-deprecations)%20(the%20%60mode.chained_assignment%60%20option%20is%20deprecated%2C%20since%20there%20is%20nothing%20left%20for%20it%20to%20control)%20%7C%0A%0A%20%20%20%20Below%3A%20set%20the%20production%20of%20every%20rice%20plot%20to%200%2C%20the%20old%20way%2C%20and%20look%20at%20the%20table%20afterwards.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(first_plots)%3A%0A%20%20%20%20def%20_chained()%3A%0A%20%20%20%20%20%20%20%20table%20%3D%20first_plots.copy()%0A%20%20%20%20%20%20%20%20table%5B%22production_kg%22%5D%5Btable%5B%22crop%22%5D%20%3D%3D%20%22Rice%22%5D%20%3D%200%20%20%23%20chained%3A%20%5Bcolumn%5D%2C%20then%20%5Brows%5D%0A%20%20%20%20%20%20%20%20return%20table%0A%0A%20%20%20%20show(_chained)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(first_plots)%3A%0A%20%20%20%20def%20_with_loc()%3A%0A%20%20%20%20%20%20%20%20table%20%3D%20first_plots.copy()%0A%20%20%20%20%20%20%20%20table.loc%5Btable%5B%22crop%22%5D%20%3D%3D%20%22Rice%22%2C%20%22production_kg%22%5D%20%3D%200%20%20%23%20one%20step%3A%20rows%20and%20column%20together%0A%20%20%20%20%20%20%20%20return%20table%0A%0A%20%20%20%20show(_with_loc)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%201.2%20%C2%B7%20Changing%20a%20selection%20never%20changes%20the%20table%20it%20came%20from%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60column%20%3D%20df%5B%22col%22%5D%60%20then%20%60column.iloc%5B0%5D%20%3D%20...%60%20changed%20%60df%60%20too%20(with%20a%20%60SettingWithCopyWarning%60)%2C%20while%20%60rice%20%3D%20df%5Bmask%5D%60%20then%20%60rice%5B%22col%22%5D%20%3D%20...%60%20did%20not%20change%20%60df%60%20(with%20the%20same%20warning).%20Two%20lines%20that%20look%20alike%20behaved%20differently.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20Neither%20changes%20%60df%60%2C%20and%20neither%20warns.%20A%20selection%20is%20yours%20to%20change.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Change%20the%20selection%20freely.%20To%20change%20the%20table%2C%20change%20the%20table%3A%20%60df.loc%5B...%5D%20%3D%20...%60.%20The%20defensive%20%60.copy()%60%20after%20a%20selection%20is%20no%20longer%20needed.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Consistent%20copy%2Fview%20behaviour%20with%20Copy-on-Write%5D(%7BV30%7D%23consistent-copy-view-behaviour-with-copy-on-write)%20(%22defensive%20%60.copy()%60%20calls%20to%20silence%20the%20warning%20are%20no%20longer%20needed%22)%20%C2%B7%20%5Bmigration%20guide%3A%20Copy-on-Write%5D(%7BGUIDE%7D%23migrating-to-copy-on-write)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(first_plots)%3A%0A%20%20%20%20def%20_change_a_column()%3A%0A%20%20%20%20%20%20%20%20table%20%3D%20first_plots.copy()%0A%20%20%20%20%20%20%20%20column%20%3D%20table%5B%22production_kg%22%5D%0A%20%20%20%20%20%20%20%20column.iloc%5B0%5D%20%3D%20999_999%20%20%23%20change%20the%20selection...%0A%20%20%20%20%20%20%20%20return%20table%20%20%23%20...and%20the%20table%20is%20as%20it%20was%0A%0A%20%20%20%20show(_change_a_column)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%201.3%20%C2%B7%20%60inplace%3DTrue%60%3A%20on%20a%20column%20it%20does%20nothing%2C%20and%20on%20most%20methods%20it%20is%20deprecated%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60df%5B%22col%22%5D.fillna(value%2C%20inplace%3DTrue)%60%20filled%20the%20column%20in%20%60df%60%20(pandas%202.3%20warned%20this%20would%20stop).%20%60df.dropna(inplace%3DTrue)%60%20changed%20%60df%60%20and%20gave%20back%20%60None%60.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60df%5B%22col%22%5D.fillna(value%2C%20inplace%3DTrue)%60%20is%20chained%20assignment%20again%3A%20it%20fills%20a%20copy%20and%20%60df%60%20keeps%20its%20gaps%2C%20with%20a%20%60ChainedAssignmentError%60%20warning.%20Since%203.1%2C%20%60inplace%3D%60%20is%20**deprecated**%20on%20the%20methods%20that%20never%20really%20worked%20in%20place%3A%20%60drop%60%2C%20%60rename%60%2C%20%60rename_axis%60%2C%20%60reset_index%60%2C%20%60set_index%60%2C%20%60dropna%60%2C%20%60drop_duplicates%60%2C%20%60sort_values%60%2C%20%60sort_index%60%2C%20%60eval%60%20and%20%60query%60%20(a%20%60Pandas4Warning%60%3A%20it%20will%20be%20removed%20in%20pandas%204).%20%60fillna%60%20and%20%60replace%60%20keep%20%60inplace%3D%60%2C%20and%20since%203.0%20they%20give%20back%20the%20table%20rather%20than%20%60None%60.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Assign%20the%20result%3A%20%60df%5B%22col%22%5D%20%3D%20df%5B%22col%22%5D.fillna(value)%60%2C%20%60df%20%3D%20df.dropna()%60.%20It%20is%20not%20slower%3A%20that%20is%20what%20%60inplace%3DTrue%60%20did%20anyway.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.1%3A%20Deprecated%20inplace%20keyword%20for%20various%20methods%5D(%7BV31%7D%23deprecated-inplace-keyword-for-various-methods)%20%C2%B7%20%5B3.0%3A%20Other%20API%20changes%5D(%7BV30%7D%23other-api-changes)%20(in-place%20methods%20return%20the%20object)%20%C2%B7%20%5Bmigration%20guide%3A%20Copy-on-Write%5D(%7BGUIDE%7D%23migrating-to-copy-on-write)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20_fill_in_place()%3A%0A%20%20%20%20%20%20%20%20plots%20%3D%20course.plots(clean%3DFalse).head(8)%5B%5B%22hh_id%22%2C%20%22plot_no%22%2C%20%22fertilizer_kg%22%5D%5D%0A%20%20%20%20%20%20%20%20plots%5B%22fertilizer_kg%22%5D.fillna(0%2C%20inplace%3DTrue)%20%20%23%20fills%20a%20copy%3A%20the%20table%20keeps%20its%20gaps%0A%20%20%20%20%20%20%20%20return%20plots%0A%0A%20%20%20%20show(_fill_in_place)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20_dropna_in_place()%3A%0A%20%20%20%20%20%20%20%20plots%20%3D%20course.plots(clean%3DFalse).head(8)%0A%20%20%20%20%20%20%20%20plots.dropna(inplace%3DTrue)%20%20%23%20still%20works%20in%203.1%2C%20but%20warns%0A%20%20%20%20%20%20%20%20return%20plots.shape%0A%0A%20%20%20%20show(_dropna_in_place)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20What%20to%20write%20now%3A%20assign%20the%20result%0A%20%20%20%20_plots%20%3D%20course.plots(clean%3DFalse).head(8)%5B%5B%22hh_id%22%2C%20%22plot_no%22%2C%20%22fertilizer_kg%22%5D%5D%0A%20%20%20%20_plots%20%3D%20_plots.dropna(subset%3D%5B%22fertilizer_kg%22%5D)%0A%20%20%20%20_plots%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%202%20%C2%B7%20Text%3A%20the%20%60str%60%20type%0A%0A%20%20%20%20In%20pandas%202%2C%20a%20column%20of%20text%20had%20the%20type%20%60object%60%3A%20a%20column%20that%20could%20hold%20any%20Python%20value%2C%20text%20or%20not.%20pandas%203%20gives%20text%20its%20own%20type%2C%20%60str%60.%20It%20holds%20only%20text%20or%20missing%20values%2C%20it%20is%20faster%2C%20and%20%60read_csv%60%2C%20%60read_excel%60%20and%20%60pd.DataFrame%60%20give%20it%20to%20every%20text%20column%20without%20being%20asked.%20Module%203%20meets%20it%20when%20reading%20the%20survey%20(%5Bsection%202%5D(%2F%3Ffile%3D20_dataframes.py))%3B%20module%205%20works%20with%20it%20(%5Bsection%202%5D(%2F%3Ffile%3D40_cleaning_and_time.py)).%0A%0A%20%20%20%20%23%23%23%202.1%20%C2%B7%20Text%20columns%20are%20%60str%60%2C%20not%20%60object%60%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60df.dtypes%60%20showed%20%60object%60%20for%20text%3B%20%60df%5B%22province%22%5D.dtype%20%3D%3D%20object%60%20was%20%60True%60%3B%20%60select_dtypes(include%3D%22object%22)%60%20picked%20the%20text%20columns.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60df.dtypes%60%20shows%20%60str%60%3B%20%60%3D%3D%20object%60%20is%20%60False%60%3B%20%60select_dtypes(include%3D%22object%22)%60%20still%20picks%20them%20in%203.1%2C%20but%20with%20a%20%60Pandas4Warning%60%3A%20it%20will%20stop.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20%60df%5B%22col%22%5D.dtype%20%3D%3D%20%22str%22%60%2C%20and%20%60select_dtypes(include%3D%22str%22)%60.%20For%20code%20that%20must%20run%20on%20both%20versions%2C%20%60pd.api.types.is_string_dtype(df%5B%22col%22%5D)%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Dedicated%20string%20data%20type%20by%20default%5D(%7BV30%7D%23dedicated-string-data-type-by-default)%20%C2%B7%20%5Bmigration%20guide%3A%20Checking%20the%20dtype%5D(%7BGUIDE%7D%23checking-the-dtype)%20%C2%B7%20%5B3.0%3A%20Other%20deprecations%5D(%7BV30%7D%23other-deprecations)%20(%60select_dtypes%60%20matching%20%60str%60%20when%20%60object%60%20is%20asked%20for)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20households%20%3D%20course.households()%0A%20%20%20%20households.dtypes%0A%20%20%20%20return%20(households%2C)%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20show(lambda%3A%20households%5B%22province%22%5D.dtype%20%3D%3D%20object)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20show(lambda%3A%20list(households.select_dtypes(include%3D%22object%22).columns))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20%23%20What%20to%20write%20now%0A%20%20%20%20show(lambda%3A%20list(households.select_dtypes(include%3D%22str%22).columns))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%202.2%20%C2%B7%20A%20text%20column%20refuses%20numbers%2C%20and%20its%20missing%20value%20is%20always%20%60NaN%60%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20An%20%60object%60%20column%20took%20anything%3A%20%60df.loc%5B0%2C%20%22crop%22%5D%20%3D%205%60%20put%20the%20number%205%20among%20the%20text.%20A%20missing%20value%20could%20be%20%60None%60%20or%20%60NaN%60.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20A%20%60str%60%20column%20raises%20%60TypeError%60%20for%20anything%20but%20text%20or%20a%20missing%20value.%20Missing%20text%20is%20always%20%60NaN%60%2C%20whatever%20was%20put%20in.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Put%20text%20in%20text%20columns%20(%60%225%22%60%2C%20not%20%605%60).%20Test%20for%20missing%20with%20%60.isna()%60%20or%20%60pd.isna(value)%60%2C%20never%20%60value%20is%20None%60.%20If%20a%20column%20really%20must%20mix%20types%2C%20make%20it%20%60object%60%20first%3A%20%60df%5B%22col%22%5D.astype(object)%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Dedicated%20string%20data%20type%20by%20default%5D(%7BV30%7D%23dedicated-string-data-type-by-default)%20%C2%B7%20%5Bmigration%20guide%3A%20setitem%20operations%20will%20now%20raise%20an%20error%20for%20non-string%20data%5D(%7BGUIDE%7D%23setitem-operations-will-now-raise-an-error-for-non-string-data)%20%C2%B7%20%5Bmigration%20guide%3A%20The%20missing%20value%20sentinel%20is%20now%20always%20NaN%5D(%7BGUIDE%7D%23the-missing-value-sentinel-is-now-always-nan)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(first_plots)%3A%0A%20%20%20%20def%20_number_into_text()%3A%0A%20%20%20%20%20%20%20%20table%20%3D%20first_plots.copy()%0A%20%20%20%20%20%20%20%20table.loc%5B0%2C%20%22crop%22%5D%20%3D%205%0A%20%20%20%20%20%20%20%20return%20table%0A%0A%20%20%20%20show(_number_into_text)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%202.3%20%C2%B7%20%60astype(str)%60%20keeps%20missing%20values%20missing%0A%0A%20%20%20%20This%20one%20matters%20for%20this%20course's%20codes.%20The%20survey%20workbook%20stores%20the%20PSGC%20codes%20as%20numbers%2C%20so%20the%20leading%20zero%20is%20gone%3B%20module%203%20brings%20it%20back%20with%20%60.astype(str).str.zfill(10)%60.%20When%20a%20code%20is%20missing%2C%20the%20two%20versions%20part%20ways.%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60astype(str)%60%20turned%20every%20value%20into%20text%2C%20missing%20ones%20included%3A%20%60NaN%60%20became%20the%20text%20%60%22nan%22%60%20(and%20%60%3CNA%3E%60%20the%20text%20%60%22%3CNA%3E%22%60)%2C%20and%20%60zfill(10)%60%20then%20made%20%60%220000000nan%22%60%2C%20a%20code%20that%20looks%20real%20and%20matches%20nothing.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60astype(str)%60%20gives%20the%20%60str%60%20type%20and%20keeps%20a%20missing%20value%20missing.%20%60zfill%60%20leaves%20it%20missing.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20%60astype(str)%60%20as%20before%3B%20count%20the%20missing%20codes%20with%20%60.isna().sum()%60%2C%20since%20they%20no%20longer%20hide%20as%20text.%20Read%20codes%20as%20text%20from%20the%20start%20where%20you%20can%3A%20%60dtype%3D%7B%7B%22psgc%22%3A%20str%7D%7D%60.%20To%20turn%20missing%20into%20text%20on%20purpose%2C%20%60.map(str)%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5Bmigration%20guide%3A%20astype(str)%20preserving%20missing%20values%5D(%7BGUIDE%7D%23astype-str-preserving-missing-values)%2C%20linked%20from%20%5B3.0%3A%20Dedicated%20string%20data%20type%20by%20default%5D(%7BV30%7D%23dedicated-string-data-type-by-default)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20Two%20codes%20as%20the%20workbook%20stores%20them%20(numbers)%2C%20one%20of%20them%20missing%0A%20%20%20%20show(lambda%3A%20pd.Series(%5B102801000%2C%20None%5D%2C%20dtype%3D%22Int64%22).astype(str).str.zfill(10))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%202.4%20%C2%B7%20Reading%20codes%20as%20a%20category%20drops%20their%20leading%20zeros%20(pandas%203.1)%0A%0A%20%20%20%20A%20category%20column%20stores%20each%20distinct%20value%20once%2C%20which%20suits%20a%20code%20that%20repeats%20on%20every%20row.%20It%20is%20tempting%20to%20read%20the%20codes%20straight%20into%20one.%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60read_csv(...%2C%20dtype%3D%7B%7B%22psgc%22%3A%20%22category%22%7D%7D)%60%20gave%20categories%20of%20text%3A%20%60%220102801000%22%60%2C%20leading%20zero%20kept.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20Since%203.1%2C%20%60dtype%3D%22category%22%60%20makes%20**number**%20categories%20when%20every%20value%20looks%20like%20a%20number%3A%20%60102801000%60%2C%20the%20zero%20gone%2C%20exactly%20as%20reading%20the%20codes%20as%20numbers%20would.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Read%20the%20codes%20as%20text%2C%20then%20make%20the%20category%3A%20%60dtype%3D%7B%7B%22psgc%22%3A%20str%7D%7D%60%2C%20then%20%60.astype(%22category%22)%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.1%3A%20read_csv()%20with%20dtype%3D%22category%22%20infers%20numeric%20and%20boolean%20categories%5D(%7BV31%7D%23read-csv-with-dtype-category-infers-numeric-and-boolean-categories)%20(%22a%20column%20of%20zero-padded%20account%20numbers%20or%20zip%20codes%20now%20gets%20integer%20categories%2C%20dropping%20the%20leading%20zeros%22)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20show(lambda%3A%20pd.read_csv(course.PATHS.survey%20%2F%20%22households.csv%22%2C%20dtype%3D%7B%22psgc%22%3A%20%22category%22%7D)%5B%22psgc%22%5D.cat.categories%5B%3A4%5D.tolist())%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20What%20to%20write%20now%3A%20text%20first%2C%20then%20the%20category%0A%20%20%20%20show(lambda%3A%20pd.read_csv(course.PATHS.survey%20%2F%20%22households.csv%22%2C%20dtype%3D%7B%22psgc%22%3A%20str%7D)%5B%22psgc%22%5D.astype(%22category%22).cat.categories%5B%3A4%5D.tolist())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%202.5%20%C2%B7%20%60.str.contains%60%20on%20missing%20text%20gives%20%60False%60%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20On%20an%20%60object%60%20column%2C%20%60.str.contains(%22Ri%22)%60%20gave%20%60NaN%60%20for%20a%20missing%20value%2C%20and%20filtering%20with%20it%2C%20%60df%5Bdf%5B%22crop%22%5D.str.contains(%22Ri%22)%5D%60%2C%20raised%20%60ValueError%3A%20Cannot%20mask%20with%20non-boolean%20array%20containing%20NA%20%2F%20NaN%20values%60.%20Hence%20the%20%60na%3DFalse%60%20in%20so%20much%20old%20code.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20On%20a%20%60str%60%20column%20the%20result%20is%20%60True%60%20or%20%60False%60%2C%20and%20a%20missing%20value%20gives%20%60False%60%2C%20so%20the%20filter%20works.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20%60df%5Bdf%5B%22crop%22%5D.str.contains(%22Ri%22)%5D%60.%20%60na%3DFalse%60%20is%20still%20accepted%20and%20still%20says%20what%20you%20mean.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Dedicated%20string%20data%20type%20by%20default%5D(%7BV30%7D%23dedicated-string-data-type-by-default)%20(the%20%60str%60%20type%20%22follows%20the%20same%20missing%20value%20semantics%20as%20the%20other%20default%20dtypes%22).%20This%20exact%20behavior%20is%20not%20spelled%20out%20in%20the%20notes%3A%20it%20was%20checked%20by%20running%20both%20versions.%20%7C%0A%0A%20%20%20%20One%20more%20for%20anyone%20who%20used%20**pandas%203.0**%3A%20with%20the%20%60str%60%20type%2C%20a%20few%20regular-expression%20methods%20briefly%20behaved%20differently%20from%20Python's%20%60re%60%20(%60%5Cd%60%2C%20%60%5Cw%60%20and%20%60%5Cs%60%20matched%20only%20ASCII%20characters).%20pandas%203.1%20put%20them%20back%20as%20they%20were%20in%20pandas%202%3A%20%5B3.1%3A%20String%20regex%20methods%20aligning%20again%20with%20Python's%20re%20module%5D(%7BV31%7D%23string-regex-methods-aligning-again-with-python-s-re-module).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20_contains()%3A%0A%20%20%20%20%20%20%20%20plots%20%3D%20course.plots(clean%3DFalse)%0A%20%20%20%20%20%20%20%20return%20plots%5Bplots%5B%22crop%22%5D.str.contains(%22Ri%22)%5D.shape%20%20%23%2014%20plots%20have%20no%20crop%3A%20they%20are%20simply%20not%20kept%0A%0A%20%20%20%20show(_contains)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%203%20%C2%B7%20Dates%20and%20times%0A%0A%20%20%20%20Module%205%20parses%20the%20interview%20dates%20(%5Bsection%203%5D(%2F%3Ffile%3D40_cleaning_and_time.py))%20and%20works%20with%20the%20monthly%20farmgate%20prices%20(%5Bsection%204%5D(%2F%3Ffile%3D40_cleaning_and_time.py)).%20Four%20changes%20meet%20you%20there.%0A%0A%20%20%20%20%23%23%23%203.1%20%C2%B7%20Dates%20are%20stored%20to%20the%20microsecond%2C%20not%20the%20nanosecond%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20Every%20date%20read%20or%20parsed%20was%20%60datetime64%5Bns%5D%60%3A%20counted%20in%20nanoseconds%20since%201%20January%201970.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20Dates%20parsed%20from%20text%2C%20read%20by%20%60read_csv%60%20or%20%60read_excel%60%2C%20or%20made%20from%20Python%20dates%20are%20%60datetime64%5Bus%5D%60%3A%20microseconds.%20Since%203.1%2C%20dates%20made%20from%20numbers%20(%60pd.to_datetime(...%2C%20unit%3D%22s%22)%60%2C%20or%20an%20Excel%20day%20count%20with%20%60unit%3D%22D%22%60)%20are%20microseconds%20too.%20Nothing%20changes%20for%20dates%20themselves%3B%20but%20turning%20a%20date%20into%20a%20whole%20number%2C%20%60astype(%22int64%22)%60%2C%20gives%20a%20number%20**1%2C000%20times%20smaller**%20than%20before.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Don't%20turn%20dates%20into%20numbers%3A%20subtract%20dates%20instead%20(%60date%20-%20date%60%20gives%20a%20duration).%20If%20something%20else%20needs%20nanoseconds%2C%20say%20so%3A%20%60.dt.as_unit(%22ns%22)%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Datetime%2Ftimedelta%20resolution%20inference%5D(%7BV30%7D%23datetime-timedelta-resolution-inference)%20%C2%B7%20%5B3.1%3A%20Datetime%2Ftimedelta%20resolution%20for%20numeric%20input%5D(%7BV31%7D%23datetime-timedelta-resolution-for-numeric-input)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20show(lambda%3A%20str(households%5B%22interview_date%22%5D.dtype))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20%23%20The%20same%20date%20as%20a%20whole%20number%3A%20microseconds%20since%201970%20(pandas%202%20gave%20nanoseconds%3A%201%2C000%20times%20larger)%0A%20%20%20%20show(lambda%3A%20households%5B%22interview_date%22%5D.astype(%22int64%22).iloc%5B0%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20%23%20What%20to%20write%20now%3A%20a%20duration%2C%20not%20a%20number.%20Days%20since%20the%20first%20interview%3A%0A%20%20%20%20show(lambda%3A%20(households%5B%22interview_date%22%5D%20-%20households%5B%22interview_date%22%5D.min()).dt.days.head(5))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%203.2%20%C2%B7%20Month%20end%20is%20%60%22ME%22%60%20for%20dates%3B%20months%20as%20periods%20stay%20%60%22M%22%60%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60resample(%22M%22)%60%2C%20%60date_range(...%2C%20freq%3D%22M%22)%60%3A%20%60%22M%22%60%20meant%20month%20end%20(and%20%60%22Q%22%60%20quarter%20end%2C%20%60%22Y%22%60%20year%20end).%20pandas%202.3%20warned%20they%20were%20deprecated.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20On%20dates%20(a%20%60DatetimeIndex%60)%2C%20%60%22M%22%60%2C%20%60%22Q%22%60%20and%20%60%22Y%22%60%20raise%20%60ValueError%60%3A%20write%20%60%22ME%22%60%2C%20%60%22QE%22%60%2C%20%60%22YE%22%60.%20On%20**periods**%20(a%20%60PeriodIndex%60%2C%20like%20the%20%60month%60%20column%20of%20%60course.prices()%60)%2C%20the%20codes%20are%20still%20%60%22M%22%60%2C%20%60%22Q%22%60%2C%20%60%22Y%22%60%2C%20and%20%60%22ME%22%60%20raises.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Dates%3A%20%60resample(%22ME%22)%60%2C%20%60resample(%22QE%22)%60%2C%20%60resample(%22YE%22)%60%20(or%20%60%22MS%22%60%2C%20%60%22QS%22%60%2C%20%60%22YS%22%60%20to%20label%20each%20month%20by%20its%20first%20day).%20Periods%3A%20%60to_period(%22M%22)%60%2C%20%60resample(%22Q%22)%60.%20The%20error%20message%20says%20which%20to%20use.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Enforced%20deprecation%20of%20aliases%20M%2C%20Q%2C%20Y%2C%20etc.%20in%20favour%20of%20ME%2C%20QE%2C%20YE%2C%20etc.%20for%20offsets%5D(%7BV30%7D%23enforced-deprecation-of-aliases-m-q-y-etc-in-favour-of-me-qe-ye-etc-for-offsets)%20%7C%0A%0A%20%20%20%20The%20example%3A%20the%20average%20farmgate%20price%20of%20palay%20across%20the%20seven%20provinces%2C%20by%20month.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20palay%20%3D%20course.prices().query(%22commodity%20%3D%3D%20'Palay'%22).groupby(%22month%22)%5B%22price%22%5D.mean()%0A%20%20%20%20palay.tail(3)%0A%20%20%20%20return%20(palay%2C)%0A%0A%0A%40app.cell%0Adef%20_(palay)%3A%0A%20%20%20%20%23%20On%20dates%3A%20%22M%22%20no%20longer%20works...%0A%20%20%20%20show(lambda%3A%20palay.to_timestamp().resample(%22M%22).mean().tail(3))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(palay)%3A%0A%20%20%20%20%23%20...write%20%22ME%22%20for%20month%20end%2C%20%22QE%22%20for%20quarter%20end%0A%20%20%20%20show(lambda%3A%20palay.to_timestamp().resample(%22QE%22).mean().tail(3))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(palay)%3A%0A%20%20%20%20%23%20On%20periods%2C%20the%20codes%20are%20unchanged%3A%20%22Q%22%20for%20quarters%0A%20%20%20%20show(lambda%3A%20palay.resample(%22Q%22).mean().tail(3))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%203.3%20%C2%B7%20%60pct_change%60%20no%20longer%20fills%20gaps%0A%0A%20%20%20%20The%20price%20files%20have%20no%20September%202023%3A%20the%20file%20never%20came.%20Put%20the%20months%20in%20a%20full%20calendar%20and%20September%20is%20a%20gap.%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60pct_change()%60%20filled%20each%20gap%20with%20the%20value%20before%20it%20(%60fill_method%3D%22pad%22%60)%20before%20computing%2C%20so%20October%202023's%20growth%20was%20measured%20against%20**August**%2C%20silently%2C%20and%20September's%20growth%20showed%200%25.%20pandas%202.3%20warned%20this%20default%20would%20go.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60pct_change()%60%20fills%20nothing%3A%20the%20growth%20into%20and%20out%20of%20the%20gap%20is%20missing.%20%60fill_method%60%20accepts%20only%20%60None%60%3B%20anything%20else%20raises%20%60ValueError%60.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20%60pct_change()%60%2C%20and%20decide%20about%20the%20gap%20yourself%3A%20leave%20it%20missing%20(honest)%2C%20or%20fill%20it%20first%2C%20saying%20so%3A%20%60.ffill().pct_change()%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Other%20removals%5D(%7BV30%7D%23other-removals)%3A%20%22Removed%20argument%20limit%20from%20%60DataFrame.pct_change()%60%2C%20%60Series.pct_change()%60%20%E2%80%A6%20the%20argument%20method%20must%20be%20set%20to%20None%22%20(the%20argument%20meant%20is%20%60fill_method%60%2C%20as%20the%20live%20error%20below%20says).%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(palay)%3A%0A%20%20%20%20%23%20The%20months%20around%20the%20gap%2C%20in%20a%20full%20calendar%0A%20%20%20%20around_gap%20%3D%20palay.reindex(pd.period_range(%222023-07%22%2C%20%222023-11%22%2C%20freq%3D%22M%22))%0A%20%20%20%20pd.DataFrame(%7B%22price%22%3A%20around_gap%2C%20%22growth%22%3A%20around_gap.pct_change()%7D)%0A%20%20%20%20return%20(around_gap%2C)%0A%0A%0A%40app.cell%0Adef%20_(around_gap)%3A%0A%20%20%20%20show(lambda%3A%20around_gap.pct_change(fill_method%3D%22pad%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%203.4%20%C2%B7%20Reading%20dates%3A%20%60date_format%60%2C%20not%20%60date_parser%60%3B%20%60day_of_week%60%2C%20not%20%60dayofweek%60%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60read_csv(...%2C%20parse_dates%3D%5B...%5D%2C%20date_parser%3D...)%60%20and%20%60infer_datetime_format%3DTrue%60%20worked%2C%20with%20warnings%20that%20they%20would%20go.%20%60.dt.dayofweek%60%20and%20%60.dt.weekday%60%20gave%20the%20day%20of%20the%20week.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60date_parser%60%2C%20%60infer_datetime_format%60%20and%20%60keep_date_col%60%20are%20gone%20from%20%60read_csv%60%3A%20%60TypeError%60.%20Since%203.1%2C%20%60.dt.dayofweek%60%2C%20%60.dt.weekday%60%2C%20%60.dt.dayofyear%60%20and%20%60.dt.daysinmonth%60%20warn%20(%60Pandas4Warning%60)%20in%20favor%20of%20the%20names%20with%20underscores.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20%60parse_dates%3D%5B%22interview_date%22%5D%2C%20date_format%3D%22%25d%2F%25m%2F%25Y%22%60%2C%20or%20read%20the%20column%20as%20text%20and%20use%20%60pd.to_datetime(...%2C%20format%3D%22%25d%2F%25m%2F%25Y%22)%60%2C%20as%20%60course.households()%60%20does.%20%60.dt.day_of_week%60%20(Monday%20is%200)%2C%20%60.dt.day_of_year%60%2C%20%60.dt.days_in_month%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Other%20removals%5D(%7BV30%7D%23other-removals)%20(%60date_parser%60%2C%20%60infer_datetime_format%60%2C%20%60keep_date_col%60)%20%C2%B7%20%5B3.1%3A%20Other%20deprecations%5D(%7BV31%7D%23other-deprecations)%20(%60dayofweek%60%20and%20the%20rest)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20show(lambda%3A%20pd.read_csv(course.PATHS.survey%20%2F%20%22households.csv%22%2C%20parse_dates%3D%5B%22interview_date%22%5D%2C%20infer_datetime_format%3DTrue).dtypes)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20What%20to%20write%20now%3A%20say%20the%20format%0A%20%20%20%20show(lambda%3A%20pd.read_csv(course.PATHS.survey%20%2F%20%22households.csv%22%2C%20parse_dates%3D%5B%22interview_date%22%5D%2C%20date_format%3D%22%25d%2F%25m%2F%25Y%22)%5B%22interview_date%22%5D.head(3))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20show(lambda%3A%20households%5B%22interview_date%22%5D.dt.dayofweek.head(3))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%204%20%C2%B7%20Selecting%20and%20setting%0A%0A%20%20%20%20%23%23%23%204.1%20%C2%B7%20%60s%5B0%5D%60%20means%20the%20label%200%2C%20never%20the%20first%20position%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20On%20a%20Series%20whose%20index%20is%20not%20numbers%20(provinces%2C%20say)%2C%20%60s%5B0%5D%60%20gave%20the%20first%20value%2C%20%60s%5B-1%5D%60%20the%20last%2C%20with%20a%20warning%20in%20pandas%202.3.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60s%5B0%5D%60%20always%20looks%20for%20the%20**label**%200.%20On%20an%20index%20of%20names%20there%20is%20none%3A%20%60KeyError%3A%200%60.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20%60s.iloc%5B0%5D%60%20for%20a%20position%2C%20%60s.loc%5B%22Iloilo%22%5D%60%20for%20a%20label.%20Module%203%20teaches%20the%20difference%20(%5Bsection%201%5D(%2F%3Ffile%3D20_dataframes.py)).%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Other%20removals%5D(%7BV30%7D%23other-removals)%3A%20%22Changed%20behavior%20of%20%60Series.__getitem__()%60%20and%20%60Series.__setitem__()%60%20to%20always%20treat%20integer%20keys%20as%20labels%2C%20never%20as%20positional%22%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20weights%20%3D%20households.groupby(%22province%22)%5B%22weight%22%5D.sum().sort_values(ascending%3DFalse)%0A%20%20%20%20show(lambda%3A%20weights%5B0%5D)%0A%20%20%20%20return%20(weights%2C)%0A%0A%0A%40app.cell%0Adef%20_(weights)%3A%0A%20%20%20%20%23%20What%20to%20write%20now%3A%20the%20first%20position%2C%20and%20a%20label%0A%20%20%20%20show(lambda%3A%20(weights.iloc%5B0%5D%2C%20weights.loc%5B%22Iloilo%22%5D))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%204.2%20%C2%B7%20Setting%20a%20value%20of%20the%20wrong%20type%20raises%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20Setting%20a%20decimal%20into%20a%20whole-number%20column%2C%20%60df.loc%5B0%2C%20%22hh_size%22%5D%20%3D%204.5%60%2C%20quietly%20turned%20the%20whole%20column%20into%20decimals%3B%20setting%20text%20turned%20it%20into%20%60object%60.%20pandas%202.3%20warned.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60TypeError%3A%20Invalid%20value%20'4.5'%20for%20dtype%20'int64'%60.%20The%20one%20exception%3A%20a%20missing%20value%20(%60np.nan%60)%20may%20still%20go%20into%20a%20whole-number%20column%2C%20which%20then%20becomes%20decimals.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Change%20the%20column's%20type%20first%2C%20on%20purpose%3A%20%60df%5B%22hh_size%22%5D%20%3D%20df%5B%22hh_size%22%5D.astype(float)%60%3B%20or%2C%20for%20whole%20numbers%20with%20gaps%2C%20the%20nullable%20%60%22Int64%22%60%20of%20module%205%20(%5Bsection%202%5D(%2F%3Ffile%3D40_cleaning_and_time.py)).%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Other%20removals%5D(%7BV30%7D%23other-removals)%3A%20%22Enforce%20banning%20of%20upcasting%20in%20in-place%20setitem-like%20operations%3B%20see%20PDEP6%22%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20def%20_decimal_into_whole()%3A%0A%20%20%20%20%20%20%20%20table%20%3D%20households.head(3).copy()%0A%20%20%20%20%20%20%20%20table.loc%5B0%2C%20%22hh_size%22%5D%20%3D%204.5%0A%20%20%20%20%20%20%20%20return%20table%0A%0A%20%20%20%20show(_decimal_into_whole)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%205%20%C2%B7%20Grouping%0A%0A%20%20%20%20%23%23%23%205.1%20%C2%B7%20Grouping%20by%20a%20category%20leaves%20out%20categories%20with%20no%20rows%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20%60groupby%60%20on%20a%20category%20column%20gave%20a%20row%20for%20**every**%20category%2C%20an%20empty%20one%20too%20(%60observed%3DFalse%60%20was%20the%20default%2C%20and%20pandas%202.3%20warned%20it%20would%20change).%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20%60observed%3DTrue%60%20is%20the%20default%3A%20only%20the%20categories%20that%20occur.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Nothing%2C%20if%20you%20want%20what%20is%20there.%20To%20list%20every%20category%2C%20including%20those%20with%20no%20rows%20(often%20what%20a%20report%20needs%3A%20%22Cassava%3A%200%22)%2C%20say%20%60observed%3DFalse%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Other%20removals%5D(%7BV30%7D%23other-removals)%3A%20%22Changed%20the%20default%20value%20of%20observed%20in%20%60DataFrame.groupby()%60%20and%20%60Series.groupby()%60%20to%20True%22%20%7C%0A%0A%20%20%20%20The%20example%3A%20the%20survey's%20crops%20as%20a%20category%20that%20also%20lists%20cassava%2C%20which%20no%20plot%20grows.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20crops%20%3D%20course.plots().assign(crop%3Dlambda%20t%3A%20pd.Categorical(t%5B%22crop%22%5D%2C%20categories%3D%5B%22Rice%22%2C%20%22Corn%22%2C%20%22Vegetables%22%2C%20%22Banana%22%2C%20%22Cassava%22%5D))%0A%20%20%20%20crops.groupby(%22crop%22)%5B%22production_kg%22%5D.size()%0A%20%20%20%20return%20(crops%2C)%0A%0A%0A%40app.cell%0Adef%20_(crops)%3A%0A%20%20%20%20%23%20What%20to%20write%20when%20the%20report%20must%20list%20every%20category%0A%20%20%20%20crops.groupby(%22crop%22%2C%20observed%3DFalse)%5B%22production_kg%22%5D.size()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%205.2%20%C2%B7%20%60groupby(...).apply%60%20no%20longer%20hands%20your%20function%20the%20grouping%20column%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20The%20function%20given%20to%20%60groupby(%22province%22).apply(...)%60%20received%20each%20group's%20rows%20**with**%20the%20%60province%60%20column%2C%20and%20pandas%202.3%20warned%20this%20would%20change.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20It%20receives%20them%20**without**%20the%20grouping%20column%3B%20asking%20for%20it%20inside%20the%20function%20raises%20%60KeyError%60.%20%60include_groups%3DTrue%60%20raises%20%60ValueError%60.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Prefer%20%60agg%60%20and%20%60transform%60%20(module%204%2C%20%5Bsections%201%20and%202%5D(%2F%3Ffile%3D30_summarize_and_combine.py))%3A%20they%20cover%20most%20of%20what%20%60apply%60%20was%20used%20for.%20If%20you%20need%20the%20group's%20name%2C%20it%20is%20the%20key%20of%20the%20result.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Other%20removals%5D(%7BV30%7D%23other-removals)%3A%20%22Removed%20specifying%20%60include_groups%3DTrue%60%20in%20%60DataFrameGroupBy.apply()%60%20and%20%60Resampler.apply()%60%22%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(households)%3A%0A%20%20%20%20show(lambda%3A%20households.groupby(%22province%22).apply(lambda%20group%3A%20group%5B%22province%22%5D.iloc%5B0%5D))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%23%205.3%20%C2%B7%20%60DataFrame.value_counts(sort%3DFalse)%60%20keeps%20the%20order%20rows%20appear%20in%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20On%20a%20table%2C%20%60value_counts(sort%3DFalse)%60%20sorted%20the%20result%20by%20the%20values%20themselves.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20It%20keeps%20the%20order%20in%20which%20each%20combination%20first%20appears%2C%20as%20%60Series.value_counts(sort%3DFalse)%60%20always%20did.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20If%20the%20order%20matters%2C%20say%20it%3A%20%60.value_counts(sort%3DFalse).sort_index()%60.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Changed%20behavior%20in%20DataFrame.value_counts()%20and%20DataFrameGroupBy.value_counts()%20when%20sort%3DFalse%5D(%7BV30%7D%23changed-behavior-in-dataframe-value-counts-and-dataframegroupby-value-counts-when-sort-false)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20course.plots()%5B%5B%22crop%22%2C%20%22irrigated%22%5D%5D.value_counts(sort%3DFalse)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%206%20%C2%B7%20Missing%20values%20in%20nullable%20columns%3A%20arithmetic%20gives%20%60%3CNA%3E%60%0A%0A%20%20%20%20Module%205%20turns%20the%20survey's%20not-stated%20codes%20into%20missing%20values%20with%20the%20**nullable**%20types%2C%20%60%22Int64%22%60%20and%20%60%22Float64%22%60%2C%20whose%20missing%20value%20is%20%60%3CNA%3E%60%20(%5Bsection%201%5D(%2F%3Ffile%3D40_cleaning_and_time.py)).%0A%0A%20%20%20%20%7C%20%7C%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20**pandas%202**%20%7C%20In%20a%20nullable%20column%2C%20arithmetic%20that%20produced%20%22not%20a%20number%22%2C%20such%20as%200%20%C3%B7%200%2C%20gave%20%60NaN%60%2C%20which%20pandas%20then%20did%20**not**%20count%20as%20missing%3A%20%60.isna()%60%20said%20%60False%60.%20%7C%0A%20%20%20%20%7C%20**pandas%203**%20%7C%20It%20gives%20%60%3CNA%3E%60%2C%20and%20%60.isna()%60%20says%20%60True%60%3A%20one%20kind%20of%20missing%2C%20counted%20the%20same%20way.%20%7C%0A%20%20%20%20%7C%20**Write%20now**%20%7C%20Nothing%20to%20change%3B%20just%20know%20that%20%60.isna().sum()%60%20now%20counts%20these%20too.%20%7C%0A%20%20%20%20%7C%20**Release%20notes**%20%7C%20%5B3.0%3A%20Changed%20treatment%20of%20NaN%20values%20in%20pyarrow%20and%20numpy-nullable%20floating%20dtypes%5D(%7BV30%7D%23changed-treatment-of-nan-values-in-pyarrow-and-numpy-nullable-floating-dtypes)%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20_harvest%20%3D%20pd.Series(%5B0%2C%201200%2C%203000%5D%2C%20dtype%3D%22Int64%22)%0A%20%20%20%20_area%20%3D%20pd.Series(%5B0%2C%201%2C%202%5D%2C%20dtype%3D%22Int64%22)%0A%20%20%20%20pd.DataFrame(%7B%22per_unit%22%3A%20_harvest%20%2F%20_area%2C%20%22missing%22%3A%20(_harvest%20%2F%20_area).isna()%7D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%207%20%C2%B7%20Removed%3A%20what%20to%20write%20instead%0A%0A%20%20%20%20Each%20of%20these%20warned%20in%20pandas%202%20and%20is%20gone%20in%20pandas%203%3A%20the%20old%20line%20stops%20with%20an%20error%2C%20named%20in%20the%20middle%20column.%20All%20are%20listed%20under%20%5B3.0%3A%20Other%20removals%5D(%7BV30%7D%23other-removals)%2C%20and%20each%20was%20run%20here.%0A%0A%20%20%20%20%7C%20old%20code%20(pandas%202)%20%7C%20in%20pandas%203%20%7C%20write%20now%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20%60df.applymap(f)%60%20%7C%20%60AttributeError%60%20%7C%20%60df.map(f)%60%20%7C%0A%20%20%20%20%7C%20%60pd.value_counts(s)%60%20%7C%20%60AttributeError%60%20%7C%20%60s.value_counts()%60%20%7C%0A%20%20%20%20%7C%20%60s.fillna(method%3D%22ffill%22)%60%20%7C%20%60TypeError%60%20%7C%20%60s.ffill()%60%20(and%20%60s.bfill()%60)%20%7C%0A%20%20%20%20%7C%20%60pd.to_numeric(s%2C%20errors%3D%22ignore%22)%60%20%7C%20%60ValueError%60%20%7C%20%60pd.to_numeric(s%2C%20errors%3D%22coerce%22)%60%2C%20then%20look%20at%20what%20became%20missing%20%7C%0A%20%20%20%20%7C%20%60pd.read_csv(...%2C%20delim_whitespace%3DTrue)%60%20%7C%20%60TypeError%60%20%7C%20%60pd.read_csv(...%2C%20sep%3Dr%22%5Cs%2B%22)%60%20%7C%0A%20%20%20%20%7C%20%60df.first(%227D%22)%60%2C%20%60df.last(%227D%22)%60%20%7C%20%60AttributeError%60%20%7C%20a%20mask%3A%20%60df.loc%5Bdf.index%20%3C%20df.index%5B0%5D%20%2B%20pd.Timedelta(days%3D7)%5D%60%20%7C%0A%20%20%20%20%7C%20%60s.bool()%60%20%7C%20%60AttributeError%60%20%7C%20%60bool(s.iloc%5B0%5D)%60%20%7C%0A%20%20%20%20%7C%20%60df.swapaxes(0%2C%201)%60%20%7C%20%60AttributeError%60%20%7C%20%60df.T%60%20%7C%0A%20%20%20%20%7C%20%60df.groupby(...%2C%20axis%3D1)%60%20%7C%20%60TypeError%60%20%7C%20%60df.T.groupby(...)%60%20%7C%0A%0A%20%20%20%20pandas%203%20also%20needs%20a%20newer%20Python%20and%20NumPy%3A%20Python%203.11%20or%20newer%20(%5B3.0%3A%20Increased%20minimum%20version%20for%20Python%5D(%7BV30%7D%23increased-minimum-version-for-python))%20and%2C%20since%203.1%2C%20NumPy%202%20(%5B3.1%3A%20Pandas%20now%20requires%20NumPy%20%3E%3D%202%5D(%7BV31%7D%23pandas-now-requires-numpy-2)).%20The%20course%20folder's%20%60uv%60%20setup%20brings%20both.%0A%0A%20%20%20%20The%20first%20three%2C%20run%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(first_plots)%3A%0A%20%20%20%20mo.vstack(%5B%0A%20%20%20%20%20%20%20%20show(lambda%3A%20first_plots%5B%5B%22area_ha%22%5D%5D.applymap(lambda%20v%3A%20round(v%2C%201)))%2C%0A%20%20%20%20%20%20%20%20show(lambda%3A%20pd.value_counts(first_plots%5B%22crop%22%5D))%2C%0A%20%20%20%20%20%20%20%20show(lambda%3A%20course.plots(clean%3DFalse)%5B%22fertilizer_kg%22%5D.head(4).fillna(method%3D%22ffill%22))%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%0A%20%20%20%20%23%23%208%20%C2%B7%20New%20in%20pandas%203%2C%20worth%20knowing%0A%0A%20%20%20%20Not%20changes%20to%20old%20code%2C%20but%20you%20will%20meet%20them%20in%20new%20code.%0A%0A%20%20%20%20%7C%20%7C%20what%20it%20does%20%7C%20release%20notes%20%7C%0A%20%20%20%20%7C%3A--%7C%3A--%7C%3A--%7C%0A%20%20%20%20%7C%20%60pd.col(%22name%22)%60%20%7C%20names%20a%20column%20inside%20%60assign%60%2C%20%60loc%60%20and%20%60%5B...%5D%60%20without%20a%20%60lambda%60%3A%20%60df.assign(yield_t%3Dpd.col(%22production_kg%22)%20%2F%20pd.col(%22area_ha%22)%20%2F%201000)%60%20%7C%20%5B3.0%3A%20Initial%20support%20for%20pd.col()%20syntax%5D(%7BV30%7D%23initial-support-for-pd-col-syntax-to-create-expressions)%20%7C%0A%20%20%20%20%7C%20%60df.select(...)%60%20%7C%20picks%20columns%20and%20computes%20new%20ones%20in%20one%20call%20(3.1)%20%7C%20%5B3.1%3A%20New%20method%20DataFrame.select%5D(%7BV31%7D%23new-method-dataframe-select)%20%7C%0A%20%20%20%20%7C%20%60df.filter(mask)%60%20%7C%20keeps%20the%20rows%20where%20a%20mask%20is%20%60True%60%2C%20handy%20at%20the%20end%20of%20a%20chain%20(3.1)%20%7C%20%5B3.1%3A%20Filtering%20with%20a%20boolean%20mask%5D(%7BV31%7D%23filtering-with-a-boolean-mask-in-dataframe-filter-and-series-filter)%20%7C%0A%0A%20%20%20%20polars%2C%20in%20module%206%2C%20works%20with%20expressions%20like%20%60pd.col%60%20throughout%20(%5Bsection%201%5D(%2F%3Ffile%3D50_polars.py)).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20course.plots().head(3).select(%22hh_id%22%2C%20%22crop%22%2C%20yield_t%3Dpd.col(%22production_kg%22)%20%2F%20pd.col(%22area_ha%22)%20%2F%201000)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
a33bc319d20531785b06b2cde1eafc43