添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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?

concat is expecting a list of (geo)dataframes as the first argument. See the docs about creating a GeoDataframe from your data. This GIS SE thread might also be useful. – Matt Oct 14, 2022 at 23:48 Please note the "Python-beginner here" in my question. I'm still struggling especially with data types and their names. – Stefan Gofferje Oct 15, 2022 at 8:08

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)
                That works, thanks. I think, I understand it also. The main point seems to be that Python or the library does not understand that the object is a DataFrame without creating an object of the type DataFrame and assigning the data to it. Is that a Python thing or specific to the library?
– Stefan Gofferje
                Oct 15, 2022 at 19:33
        

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.