Select to view content in your preferred language

Received Type Error on Esri Python API Course

137
2
Friday
AvigailVargas
New Contributor

I am currently on ArcGIS Pro 3.3 and I am learning how to make a line chart through a Spatially Exported Data Frame (SEDF) using their ArcGIS Pro Python API, but I keep getting an error from using the .set_index object.

 

import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor
import matplotlib.pyplot as plt

# add the magic command to keep charts inline
%matplotlib inline

sedf = pd.DataFrame.spatial.from_featureclass(r'G:\share_file\avargas\Esri Training\VisualPythonAPI\VisualPythonAPI\FirePoints.gdb\FireEvents_MT')

wildfires_df = sedf[sedf["CauseCat"] == "Natural"]

wildfires_by_month = wildfires_df.set_index("StartDate").groupby(pd.Grouper(freq='M')).count()

 

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

What exactly is the error you're getting? Can you paste the full text?

When you make a Grouper object, try explicitly stating the key. I don't really understand why the index is being set prior to grouping.

wildfires_by_month = wildfires_df.groupby(pd.Grouper(freq='M', key='StartDate')).count()

- Josh Carlson
Kendall County GIS
0 Kudos
AvigailVargas
New Contributor

This is a screenshot of the error I am getting:

AvigailVargas_0-1718998250824.png

I'm really just following an online lesson plan, but it is clearly outdated. I tried using the line of code you suggested but nothing really changed, I get the same exact error.

 

0 Kudos