User Tools

Site Tools


tutorials:python_quick_reference

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
tutorials:python_quick_reference [2021/07/29 20:00]
marcus.williams [S]
tutorials:python_quick_reference [2021/08/06 14:20]
marcus.williams [Data import and export]
Line 76: Line 76:
 <​code>​ <​code>​
 df_structure = gpd.read_file(myLayers.gdb,​ layer='​structure'​) df_structure = gpd.read_file(myLayers.gdb,​ layer='​structure'​)
 +</​code>​
 +
 +Round trip export/​import for json files, as Python dictionaries or lists. Requires ''​import json''​.
 +
 +<​code>​
 +filename = '​folderX/​list_CEUDSector_ind.json'​
 +with open(filename,​ '​w',​ encoding='​utf-8'​) as f:
 +    json.dump(l_CEUDSector_ind,​ f, ensure_ascii=False,​ indent=4)
 +</​code>​
 +
 +<​code>​
 +filename = '​folderX/​list_CEUDSector_ind.json'​
 +with open(filename) as data_file:
 +    l_CEUDSector_ind= json.load(data_file)
 </​code>​ </​code>​
  
Line 105: Line 119:
 <​code>​ <​code>​
 pt_structure = pd.pivot_table(df_structure,​ pt_structure = pd.pivot_table(df_structure,​
-    '​OBJECTID',​+    ​values='​OBJECTID',​
     index=['​propType'​],​     index=['​propType'​],​
     columns=['​strucType'​],​     columns=['​strucType'​],​
     margins=True,​     margins=True,​
-    aggfunc=len)+    aggfunc=np.sum)
 </​code>​ </​code>​
 [[http://​pandas.pydata.org/​pandas-docs/​stable/​generated/​pandas.pivot_table.html#​pandas.pivot_table|ref]] | [[http://​pandas.pydata.org/​pandas-docs/​stable/​generated/​pandas.pivot_table.html#​pandas.pivot_table|ref]] |
tutorials/python_quick_reference.txt ยท Last modified: 2021/08/06 22:20 by marcus.williams