Hello everyone,
I am trying to update a map based on a pre-built template. However, after everything ran successfully (python code below), the shapefile that was updated did not show up on the map. Its symbology was also changed from "Quantities: Graduated colors" to "Features: Single symbol". I'm not sure what I did wrong? Any pointer is appreciated. Thanks!

Steps that I did:
- Read the original shapefile in the template with preset symbology.
- Copied that shapefile to a new one.
- Added a csv file then joined it with the newly created shapefile.
- Updated existing field in the new feature with the values in the csv file.
- Change the data source from the original shapefile to the new one.
- Refreshed TOC and ActiveView then exported to a new mxd file.
I opened the new mxd file. The data source is correctly updated to the new file. Values in the attribute table were also correct.
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> ntpath
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token">### set project directory</SPAN>
project_dir <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>expanduser<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'~/Projects/'</SPAN><SPAN class="punctuation token">)</SPAN>
mxd_dir <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>project_dir<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'GIS/mxd/'</SPAN><SPAN class="punctuation token">)</SPAN>
gis_dir <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>project_dir<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'GIS/shapefile'</SPAN><SPAN class="punctuation token">)</SPAN>
env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>project_dir<SPAN class="punctuation token">,</SPAN> gis_dir<SPAN class="punctuation token">)</SPAN>
year <SPAN class="operator token">=</SPAN> <SPAN class="string token">'2019'</SPAN>
dframe <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Baseline'</SPAN>
csv_file <SPAN class="operator token">=</SPAN> <SPAN class="string token">'sample.csv'</SPAN>
<SPAN class="comment token">### open mxd template file</SPAN>
mxd_file <SPAN class="operator token">=</SPAN> <SPAN class="string token">"my_template.mxd"</SPAN>
full_path <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>mxd_dir <SPAN class="operator token">+</SPAN> mxd_file<SPAN class="punctuation token">)</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>full_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### list data frame in the mxd file</SPAN>
df <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> dframe<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">### List layers</SPAN>
layers <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### This is the shapefile in the template with preset symbology</SPAN>
inFeatures <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>gis_dir<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Q_"</SPAN> <SPAN class="operator token">+</SPAN> dframe <SPAN class="operator token">+</SPAN> <SPAN class="string token">".shp"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>inFeatures<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### make a copy</SPAN>
outFeatures <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>gis_dir<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"output"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Q_"</SPAN> <SPAN class="operator token">+</SPAN> dframe <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_"</SPAN> <SPAN class="operator token">+</SPAN> year <SPAN class="operator token">+</SPAN> <SPAN class="string token">".shp"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN>in_features <SPAN class="operator token">=</SPAN> inFeatures<SPAN class="punctuation token">,</SPAN> out_feature_class <SPAN class="operator token">=</SPAN> outFeatures<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### join then do field calculator on the new feature </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>in_features <SPAN class="operator token">=</SPAN> outFeatures<SPAN class="punctuation token">,</SPAN> out_layer <SPAN class="operator token">=</SPAN> <SPAN class="string token">'new_lyr'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeTableView_management<SPAN class="punctuation token">(</SPAN>in_table <SPAN class="operator token">=</SPAN> csv_file<SPAN class="punctuation token">,</SPAN> out_view <SPAN class="operator token">=</SPAN> <SPAN class="string token">'csv_ec'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddJoin_management<SPAN class="punctuation token">(</SPAN>in_layer_or_view <SPAN class="operator token">=</SPAN> <SPAN class="string token">'new_lyr'</SPAN><SPAN class="punctuation token">,</SPAN> in_field <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ID'</SPAN><SPAN class="punctuation token">,</SPAN> join_table <SPAN class="operator token">=</SPAN> <SPAN class="string token">'csv_ec'</SPAN><SPAN class="punctuation token">,</SPAN> join_field <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ID'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'new_lyr'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"Q_"</SPAN> <SPAN class="operator token">+</SPAN> dframe <SPAN class="operator token">+</SPAN> <SPAN class="string token">"_"</SPAN> <SPAN class="operator token">+</SPAN> year <SPAN class="operator token">+</SPAN> <SPAN class="string token">".Q"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"!"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Q_"</SPAN> <SPAN class="operator token">+</SPAN> dframe <SPAN class="operator token">+</SPAN> <SPAN class="string token">".csv"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">".Q_new!"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"PYTHON"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### update data source</SPAN>
<SPAN class="keyword token">for</SPAN> lyr <SPAN class="keyword token">in</SPAN> layers<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> dframe <SPAN class="keyword token">in</SPAN> lyr<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">:</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>replaceDataSource<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>gis_dir<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"output"</SPAN><SPAN class="punctuation token">,</SPAN> dframe<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SHAPEFILE_WORKSPACE"</SPAN><SPAN class="punctuation token">,</SPAN>
os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>ntpath<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>outFeatures<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### Update Layout View</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RefreshTOC<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### save to new mxd file</SPAN>
new_mxd <SPAN class="operator token">=</SPAN> <SPAN class="string token">"new_Q_"</SPAN> <SPAN class="operator token">+</SPAN> year<SPAN class="punctuation token">.</SPAN>upper<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">".mxd"</SPAN>
new_mxd_path <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>mxd_dir <SPAN class="operator token">+</SPAN> new_mxd<SPAN class="punctuation token">)</SPAN>
mxd<SPAN class="punctuation token">.</SPAN>saveACopy<SPAN class="punctuation token">(</SPAN>new_mxd<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">### Clean up the MapDocument object by deleting it</SPAN>
<SPAN class="keyword token">del</SPAN> mxd<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>