<?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: Updating records in a dataframe in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002825#M5220</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/419229"&gt;@ejuser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Pivot method in pandas might do what you are looking for. See below:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import pandas as pd

df = pd.read_csv(path to csv file)
df.pivot(index='Unit', columns='GrowYrAbr', values=['AvgHt','MaxHt','WstHt','AvgHt21','MaxHt21','WstHt21','AvgHt22','MaxHt22','WstHt22','AvgHt23','MaxHt23','WstHt23'])&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MehdiPira1_0-1605750163573.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/510i1733A451E9C5B9B8/image-size/large?v=v2&amp;amp;px=999" role="button" title="MehdiPira1_0-1605750163573.png" alt="MehdiPira1_0-1605750163573.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;you can change the index and columns if this is not the result you are after.&lt;/P&gt;&lt;P&gt;Hope that's helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Nov 2020 01:47:10 GMT</pubDate>
    <dc:creator>MehdiPira1</dc:creator>
    <dc:date>2020-11-19T01:47:10Z</dc:date>
    <item>
      <title>Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002811#M5219</link>
      <description>&lt;P&gt;I am new to panda dataframes and would really appreciate some guidance on how to transpose the GrothYrAbr for each Unit (3 records everytime) into the first row of each unit based on the dataframe structure shown below.&amp;nbsp; Thanks kindly.&lt;/P&gt;&lt;TABLE width="1010"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="67"&gt;Unit&lt;/TD&gt;&lt;TD width="67"&gt;GrowthYr&lt;/TD&gt;&lt;TD width="72"&gt;GrowYrAbr&lt;/TD&gt;&lt;TD width="67"&gt;AvgHt&lt;/TD&gt;&lt;TD width="67"&gt;MaxHt&lt;/TD&gt;&lt;TD width="67"&gt;WstHt&lt;/TD&gt;&lt;TD width="67"&gt;AvgHt21&lt;/TD&gt;&lt;TD width="67"&gt;MaxHt21&lt;/TD&gt;&lt;TD width="67"&gt;WstHt21&lt;/TD&gt;&lt;TD width="67"&gt;AvgHt22&lt;/TD&gt;&lt;TD width="67"&gt;MaxHt22&lt;/TD&gt;&lt;TD width="67"&gt;WstHt22&lt;/TD&gt;&lt;TD width="67"&gt;AvgHt23&lt;/TD&gt;&lt;TD width="67"&gt;MaxHt23&lt;/TD&gt;&lt;TD width="67"&gt;WstHt23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;65110260&lt;/TD&gt;&lt;TD&gt;2021&lt;/TD&gt;&lt;TD&gt;21&lt;/TD&gt;&lt;TD&gt;0.59&lt;/TD&gt;&lt;TD&gt;0.94&lt;/TD&gt;&lt;TD&gt;9.58&lt;/TD&gt;&lt;TD&gt;0.59&lt;/TD&gt;&lt;TD&gt;0.94&lt;/TD&gt;&lt;TD&gt;9.58&lt;/TD&gt;&lt;TD&gt;0.85&lt;/TD&gt;&lt;TD&gt;1.30&lt;/TD&gt;&lt;TD&gt;10.05&lt;/TD&gt;&lt;TD&gt;1.12&lt;/TD&gt;&lt;TD&gt;1.68&lt;/TD&gt;&lt;TD&gt;10.52&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&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TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 19 Nov 2020 00:40:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002811#M5219</guid>
      <dc:creator>ejuser</dc:creator>
      <dc:date>2020-11-19T00:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002825#M5220</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/419229"&gt;@ejuser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Pivot method in pandas might do what you are looking for. See below:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import pandas as pd

df = pd.read_csv(path to csv file)
df.pivot(index='Unit', columns='GrowYrAbr', values=['AvgHt','MaxHt','WstHt','AvgHt21','MaxHt21','WstHt21','AvgHt22','MaxHt22','WstHt22','AvgHt23','MaxHt23','WstHt23'])&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MehdiPira1_0-1605750163573.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/510i1733A451E9C5B9B8/image-size/large?v=v2&amp;amp;px=999" role="button" title="MehdiPira1_0-1605750163573.png" alt="MehdiPira1_0-1605750163573.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;you can change the index and columns if this is not the result you are after.&lt;/P&gt;&lt;P&gt;Hope that's helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 01:47:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002825#M5220</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2020-11-19T01:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002844#M5221</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the suggestion. When I attempt to run it, I get the following:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="ansi-red-fg"&gt;ValueError&lt;/SPAN&gt;: Index contains duplicate entries, cannot reshape&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is due to the Unit not being unique. Each unit is repeated three times in the dataframe.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 04:09:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002844#M5221</guid>
      <dc:creator>ejuser</dc:creator>
      <dc:date>2020-11-19T04:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002869#M5223</link>
      <description>&lt;P&gt;Not sure the efficaccy of the solution you are after but this is how you go about it.&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 pandas as pd
#Pivot df to send GrowthYrs to columns and come up with new frame
df1 = pd.pivot_table(df, values=['GrowYrAbr', 'AvgHt', 'MaxHt'], index=['Unit'],columns=['GrowthYr'])

#Step above results in mutliindex, so collapse it by renaming column using a list comprehension with the help of fstrings
df1.columns = [f'{a}_{b}' for a, b in df1.columns]

#merge new frame to old
df2=pd.merge(df,df1, how ='left', on='Unit')

print(df2)

 Unit  GrowthYr  GrowYrAbr  AvgHt  MaxHt  AvgHt_21  AvgHt_22  AvgHt_23  \
0  2021        21       0.59   0.94   9.58     1.495       NaN       NaN   
1  2022        22       0.85   1.30  10.05       NaN     1.865       NaN   
2  2023        23       1.12   1.68  10.52       NaN       NaN     2.245   
3  2021        21       1.41   2.05   5.61     1.495       NaN       NaN   
4  2022        22       1.71   2.43   6.14       NaN     1.865       NaN   
5  2023        23       2.01   2.81   6.67       NaN       NaN     2.245   

   GrowYrAbr_21  GrowYrAbr_22  GrowYrAbr_23  MaxHt_21  MaxHt_22  MaxHt_23  
0           1.0           NaN           NaN     7.595       NaN       NaN  
1           NaN          1.28           NaN       NaN     8.095       NaN  
2           NaN           NaN         1.565       NaN       NaN     8.595  
3           1.0           NaN           NaN     7.595       NaN       NaN  
4           NaN          1.28           NaN       NaN     8.095       NaN  
5           NaN           NaN         1.565       NaN       NaN     8.595 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 06:46:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002869#M5223</guid>
      <dc:creator>wwnde</dc:creator>
      <dc:date>2020-11-19T06:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002927#M5225</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I appreciate your insight. My goal is to flatten the table such that each unit has growth model heights for year 2021, 2022, 2023 on one row so it can be joined with a feature class in a one-to-one relationship.&lt;/P&gt;&lt;P&gt;I wonder if I can store the attributes for the three years of growth for each unit and write it out in another file as one record as opposed to three? I will continue to explore this. Thanks for taking the time to respond.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 13:04:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1002927#M5225</guid>
      <dc:creator>ejuser</dc:creator>
      <dc:date>2020-11-19T13:04:53Z</dc:date>
    </item>
    <item>
      <title>Re: Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1003350#M5227</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/419229"&gt;@ejuser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Depending on what aggregation function you want the 3 years for one unit code in the output, try this out. I've used sum and you can change the &lt;STRONG&gt;aggfunc&lt;/STRONG&gt; to mean,&amp;nbsp; ....&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df.pivot_table(values=['GrowYrAbr','AvgHt','MaxHt','WstHt','AvgHt21','MaxHt21','WstHt21','AvgHt22','MaxHt22','WstHt22','AvgHt23','MaxHt23','WstHt23'],
    columns='Unit',
    aggfunc='sum',
    fill_value=0,
    margins=False,
    dropna=True,)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MehdiPira1_0-1605855269765.png" style="width: 246px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/648iF753F697CA39B1E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MehdiPira1_0-1605855269765.png" alt="MehdiPira1_0-1605855269765.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 06:56:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1003350#M5227</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2020-11-20T06:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1003444#M5228</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="UserName lia-user-name lia-user-rank-Esri-Contributor lia-component-message-view-widget-author-username"&gt;&lt;A href="https://community.esri.com/t5/user/viewprofilepage/user-id/43250" target="_self"&gt;&lt;SPAN class=""&gt;MehdiPira1&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;It is extremely helpful being made aware of the aggregation function. I feel as though the groupby function might be of value to me also. I will continue to explore these approaches and update the thread with my findings - thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 14:47:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1003444#M5228</guid>
      <dc:creator>ejuser</dc:creator>
      <dc:date>2020-11-20T14:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Updating records in a dataframe</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1056562#M6041</link>
      <description>&lt;P&gt;Thanks for the suggestion. When I attempt to run it, I get the following:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="ansi-red-fg"&gt;ValueError&lt;/SPAN&gt;: Index contains duplicate entries, cannot reshape&lt;/PRE&gt;&lt;P&gt;Try to remove duplicate using drop_duplicates(). Pandas &lt;A href="http://net-informations.com/ds/pda/rem.htm" target="_self"&gt;drop_duplicates()&lt;/A&gt; returns only the dataframe's unique values.&lt;/P&gt;&lt;P&gt;drop_duplicates(subset=None, keep="first", inplace=False)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 06:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/updating-records-in-a-dataframe/m-p/1056562#M6041</guid>
      <dc:creator>ricslator</dc:creator>
      <dc:date>2021-05-11T06:39:55Z</dc:date>
    </item>
  </channel>
</rss>

