<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Populated calculated Fields via Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/populated-calculated-fields-via-python/m-p/1242827#M67822</link>
    <description>&lt;P&gt;Does it need to be dynamic?&lt;/P&gt;&lt;P&gt;Seems you could open a copy of the Excel file, select ALL, Copy, Paste Special (Values).&lt;/P&gt;&lt;P&gt;Then feed this excel into the script as the calculated cells will be the value now, and not the formula.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
    <pubDate>Tue, 20 Dec 2022 21:49:14 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2022-12-20T21:49:14Z</dc:date>
    <item>
      <title>Populated calculated Fields via Python</title>
      <link>https://community.esri.com/t5/python-questions/populated-calculated-fields-via-python/m-p/1242746#M67821</link>
      <description>&lt;P&gt;I have a simple script here that is:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;reading through a folder for excel files.&lt;/LI&gt;&lt;LI&gt;Reads each one and combines the multiple excel files into a main excel file.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My issue here is that two of those fields in the excel file are calculated based off values in a couple other fields....and they do not populate when they write to the new excel file&lt;/P&gt;&lt;P&gt;I saw that you could calculate them in python but have NO idea how to do that..&lt;/P&gt;&lt;P&gt;In the EXCEL FILE on the field&lt;/P&gt;&lt;P&gt;=IF(I2="value1","Value2",IF(I2="Value3","Value4",IF(I2="Value5","Value4","")))&lt;/P&gt;&lt;P&gt;Can I loop through the new Excel file and create an if field reading the Column names and populate this data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Im not sure how to Update the newly created excel file after its created or should I do it while its reading the individual excel files ???&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Thanks in Advance.... Cheers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# READ EXCEL FILE AND LOOP THROUGH EACH ROW VALUE

    if row['Field1'].month == "value1":
        # set Field 4 = "some value 1"
    elif row['Field1'].month == "value2":
        # set Field 4 = "some value 2"
    else:
        # set Field 4 = "some value 3"      &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import glob
import pandas as pd
import warnings

# specifying the path to csv files
path = r"C:\Users\CreateMasterExcelFile"
 
# csv files in the path
file_list = glob.glob(path + "/*.xlsx")
 
# list of excel files we want to merge.pd.read_excel(file_path) reads the excel data into pandas dataframe.
excl_list = []
excl_nameList = []

for file in file_list:
    warnings.simplefilter(action='ignore', category=UserWarning)
    print(file)

    excl_nameList.append(file)
    excl_list.append(pd.read_excel(file, index_col=None, na_values=['NA'], usecols="A:D,H,I"))

# create a new dataframe to store the
# merged excel file.
excl_merged = pd.DataFrame()
 
for excl_file in excl_list:
     
    # appends the data into the excl_merged
    # dataframe.
    excl_merged = excl_merged.append(
      excl_file, ignore_index=True)
 
# exports the dataframe into excel file with
# specified name.
excl_merged.to_excel('total_records.xlsx', index=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 17:32:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populated-calculated-fields-via-python/m-p/1242746#M67821</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2022-12-20T17:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Populated calculated Fields via Python</title>
      <link>https://community.esri.com/t5/python-questions/populated-calculated-fields-via-python/m-p/1242827#M67822</link>
      <description>&lt;P&gt;Does it need to be dynamic?&lt;/P&gt;&lt;P&gt;Seems you could open a copy of the Excel file, select ALL, Copy, Paste Special (Values).&lt;/P&gt;&lt;P&gt;Then feed this excel into the script as the calculated cells will be the value now, and not the formula.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 21:49:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populated-calculated-fields-via-python/m-p/1242827#M67822</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-12-20T21:49:14Z</dc:date>
    </item>
  </channel>
</rss>

