<?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: convert Pandas to Arcpy : TypeError: string indices must be integers_arcgis pro in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/convert-pandas-to-arcpy-typeerror-string-indices/m-p/545727#M23904</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;df is going to be a text reference not an object that you can slice on the second line.&lt;/P&gt;&lt;P&gt;Throw a print statement in there and see what I mean&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Jul 2020 16:07:55 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2020-07-29T16:07:55Z</dc:date>
    <item>
      <title>convert Pandas to Arcpy : TypeError: string indices must be integers_arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/convert-pandas-to-arcpy-typeerror-string-indices/m-p/545726#M23903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I already have a Python pandas code to use interpolation to calculate the time for Null cells. The input and output of this code is Excel(this excel comes from a shape file) file. Now I want to do run this code as a part of the Model builder in Arcgis pro. I try to use Arcpy but I face this error continuously: "TypeError: string indices must be integers".&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/501668_Captwwwwwure.PNG" /&gt;&lt;/P&gt;&lt;P&gt;In pandas, the attribute table automatically read as integer and matrix, so I easy search on two-column in data and then used interpolation to fill Null, but in arcpy it read it as String, so I cant search for any column, and I can't do anything to convert it.&lt;/P&gt;&lt;P&gt;as a summary: the code first read attribute table, then check"FS_TYPE", if it is equal to"STOP" then use "MEAS" and "TS" column to calculate "TS" of STOP. The code works properly in Pandas but I can't run it on Arcpy.&lt;/P&gt;&lt;P&gt;**This in normal code in Pandas:**&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;OL&gt;&lt;LI&gt;import pandas as pd&lt;BR /&gt;import numpy as np&lt;BR /&gt;&lt;STRONG&gt;path = "C:/Users/"&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;df = pd.read_excel(path + "ULID443OCT30_TIMESPACE.xlsx")&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;df1 = df[["MEAS"]]&lt;/STRONG&gt;&lt;BR /&gt;for i, row in df.iterrows():&lt;BR /&gt; if row["F_TYPE"] =="STOP":&lt;BR /&gt; continue&lt;BR /&gt; else:&lt;BR /&gt; df1.loc[i,"TS"] = pd.to_datetime(row["TS"])&lt;BR /&gt;def calcSlope(ts1, ts2, meas1, meas2):&lt;BR /&gt; if meas2 - meas1 &amp;lt;= 10**-10:&lt;BR /&gt; result = 0&lt;BR /&gt; else:&lt;BR /&gt; result = (ts2-ts1)/(meas2-meas1)&lt;BR /&gt; return result&lt;/LI&gt;&lt;LI&gt;......&lt;/LI&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;**This is the code that I converted to Arcpy**&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import arcpy&lt;BR /&gt;&lt;BR /&gt; &lt;STRONG&gt;df = arcpy.GetParameterAsText (0)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; df1 = df[["MEAS"]]&lt;/STRONG&gt;&lt;BR /&gt; for i, row in df.iterrows():&lt;BR /&gt; if row["F_TYPE"] =="STOP":&lt;BR /&gt; continue&lt;BR /&gt; else:&lt;BR /&gt; df1.loc[i,"TS"] = arcpy.to_datetime(row["TS"])&lt;BR /&gt; def calcSlope(TS1, TS2, meas1, meas2):&lt;BR /&gt; if meas2 - meas1 &amp;lt;= 10**-10:&lt;BR /&gt; result = 0&lt;BR /&gt; else:&lt;BR /&gt; result = (TS2-TS1)/(meas2-meas1)&lt;BR /&gt; return result&lt;BR /&gt;...&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Jul 2020 09:52:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/convert-pandas-to-arcpy-typeerror-string-indices/m-p/545726#M23903</guid>
      <dc:creator>aliafshar</dc:creator>
      <dc:date>2020-07-29T09:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: convert Pandas to Arcpy : TypeError: string indices must be integers_arcgis pro</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/convert-pandas-to-arcpy-typeerror-string-indices/m-p/545727#M23904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;df is going to be a text reference not an object that you can slice on the second line.&lt;/P&gt;&lt;P&gt;Throw a print statement in there and see what I mean&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Jul 2020 16:07:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/convert-pandas-to-arcpy-typeerror-string-indices/m-p/545727#M23904</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-07-29T16:07:55Z</dc:date>
    </item>
  </channel>
</rss>

