Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow
, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this community
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Python-beginner here. I'm trying to fix a deprecation warning in:
df = gpd.GeoDataFrame(columns=['location', 'geometry'])
for dir, subdir, files in os.walk(StartDir):
for fname in files:
if fname.endswith(".tif"):
df = df.append({'location': fname, 'geometry': getBounds(os.path.join(dir+"/", fname))}, ignore_index=True)
by replacing the append line with:
df = gpd.pd.concat(df,{'location': fname, 'geometry': getBounds(os.path.join(dir+"/", fname))}, ignore_index=True)
which leads to this error message:
TypeError: first argument must be an iterable of pandas objects, you passed an object of type "GeoDataFrame"
What am I missing?
–
–
In order for concat
to work, it needs a list of dataframes. You can make a temporary dataframe in each iteration of your loop using the dictionary notation {}
you already have, but by passing it to the pd.DataFrame
constructor, like so:
df = gpd.GeoDataFrame(columns=['location', 'geometry'])
for dir, subdir, files in os.walk(StartDir):
for fname in files:
if fname.endswith(".tif"):
# create a temporary df with the desired values, it necessary to specify the index
df_to_append = gpd.pd.DataFrame({'location': fname, 'geometry': getBounds(os.path.join(dir+"/", fname))}, index=[0])
# here the temporary dataframe is appended to the original dataframe each iteration of the loop
# by passing a list [] of the orignal dataframe and the temporary one to `pd.concat()`
# importantly, the index is now ignored to renumber each row sequentially
df = gpd.pd.concat([df, df_to_append], ignore_index=True)
–
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.