Geopandas Dataframe이 인덱스 오류를 반환하는 이유 (Why is the Geopandas Dataframe returning an Index Error)


문제 설명

Geopandas Dataframe이 인덱스 오류를 반환하는 이유 (Why is the Geopandas Dataframe returning an Index Error)

저는 VS Code 노트북에서 geopandas 0.6.1과 pandas 1.0.0을 사용하고 있습니다. 오늘 작업하는 동안 겉보기에 유효한 geopandas 데이터 프레임에서 geopandas 함수 head()를 호출하여 아래 오류가 발생했다는 사실에 놀랐습니다.

gpd.columns 및 gpd.shape와 같은 메소드는 정상적으로 작동하고 예상 결과를 반환합니다. .iloc은 예상 레코드를 반환합니다. 예:

for item in new_west_df.columns.values.tolist():
    print(item)

TYPE
NWID
LICENCE
TRADE_NAME
LICENCEE_NAME
CIVIC_ADDRESS
LICENCE_DESCRIPTION
YEAR_OPENED
APPROVED_DATE
SIC
SIC_GROUP
CIVIC_POSTAL_CODE
geometry

그러나 columns() 및 .geometry는 아래 오류를 발생시킵니다. 문제에 대한 내 연구에서 이러한 조건과 유사한 시나리오는 없었으며 오류를 읽으면 근본 원인을 이해할 수 없습니다.

IndexError                                Traceback (most recent call last)
/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
‑‑> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/IPython/lib/pretty.py in pretty(self, obj)
    397                         if cls is not object \
    398                                 and callable(cls.__dict__.get('__repr__')):
‑‑> 399                             return _repr_pprint(obj, self, cycle)
    400 
    401             return _default_pprint(obj, self, cycle)

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    687     """A pprint that just redirects to the normal repr function."""
    688     # Find newlines and replace them with p.break_()
‑‑> 689     output = repr(obj)
    690     for idx,output_line in enumerate(output.splitlines()):
    691         if idx:

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/pandas/core/series.py in __repr__(self)
   1370             min_rows=min_rows,
   1371             max_rows=max_rows,
‑> 1372             length=show_dimensions,
   1373         )
   1374         result = buf.getvalue()

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/pandas/core/series.py in to_string(self, buf, na_rep, float_format, header, index, length, dtype, name, max_rows, min_rows)
   1436             max_rows=max_rows,
   1437         )
‑> 1438         result = formatter.to_string()
   1439 
   1440         # catch contract violations

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/pandas/io/formats/format.py in to_string(self)
    359 
    360         fmt_index, have_header = self._get_formatted_index()
‑‑> 361         fmt_values = self._get_formatted_values()
    362 
    363         if self.truncate_v:

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/pandas/io/formats/format.py in _get_formatted_values(self)
    346             None,
    347             float_format=self.float_format,
‑‑> 348             na_rep=self.na_rep,
    349         )
    350 

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/pandas/io/formats/format.py in format_array(values, formatter, float_format, na_rep, digits, space, justify, decimal, leading_space)
   1172     )
   1173 
‑> 1174     return fmt_obj.get_result()
   1175 
   1176 

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/pandas/io/formats/format.py in get_result(self)
   1203 
   1204     def get_result(self) ‑> List[str]:
‑> 1205         fmt_values = self._format_strings()
   1206         return _make_fixed_width(fmt_values, self.justify)
   1207 

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/pandas/io/formats/format.py in _format_strings(self)
   1483             values = values._values
   1484 
‑> 1485         formatter = values._formatter(boxed=True)
   1486 
   1487         if is_categorical_dtype(values.dtype):

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/geopandas/array.py in _formatter(self, boxed)
   1009                 # dummy heuristic based on 10 first geometries that should
   1010                 # work in most cases
‑> 1011                 xmin, ymin, xmax, ymax = self[~self.isna()][:10].total_bounds
   1012                 if (
   1013                     (‑180 <= xmin <= 180)

/Library/Frameworks/anaconda3/envs/vm/lib/python3.7/site‑packages/geopandas/array.py in total_bounds(self)
    750         return np.array(
    751             (
‑‑> 752                 b[:, 0].min(),  # minx
    753                 b[:, 1].min(),  # miny
    754                 b[:, 2].max(),  # maxx

IndexError: too many indices for array

참조 솔루션

방법 1:

This is a bug that was fixed in GeoPandas 0.6.2 (https://github.com/geopandas/geopandas/releases/tag/v0.6.2), so if you upgrade geopandas, it should be solved.

(by BBirdselljoris)

참조 문서

  1. Why is the Geopandas Dataframe returning an Index Error (CC BY‑SA 2.5/3.0/4.0)

#geopandas #Python #pandas






관련 질문

{'northeast': {'lat':}, 'southwest': {'lat': }}(Google 지도) Python에서 다각형을 만드는 방법 (How to create Polygon out of {'northeast': {'lat':}, 'southwest': {'lat': }} (google maps) Python)

모양이 교차하는 다각형의 수를 어떻게 계산합니까? (How can I count the number of polygons a shape intersects?)

GeoPandas를 사용하여 Python에서 GRASS 벡터 데이터 소스 읽기 (Read GRASS vector datasources in Python using GeoPandas)

어떤 점에 포함된 영역을 찾는 Geopandas (Geopandas to locate which area does a point contains)

Geopandas Dataframe이 인덱스 오류를 반환하는 이유 (Why is the Geopandas Dataframe returning an Index Error)

여러 선스트링으로 구성된 shapefile을 분할하는 방법 (How to split a shapefile compose of multiple linestrings)

LineString 유형의 개체는 JSON 직렬화가 불가능합니다. (Object of type LineString is not JSON serializable)

큰 geotif 파일 열기 (Open large geotif file)

점이 있는 geopandas 데이터 프레임에서 다각형 만들기 (Creating a polygon from a geopandas dataframe with points)

여러 소스 및 대상 노드에 대한 Networkx 최단 경로 분석 (Networkx Shortest Path Analysis on multiple source and target nodes)

위도/경도 포인트가 다각형 내에 있는지 어떻게 확인합니까? (How do I determine if a lat/long point is within a polygon?)

Geodataframe.explore() 오류: __init__() 누락된 1개의 필수 위치 인수: '위치' (Geodataframe.explore() error: __init__() missing 1 required positional argument: 'location')







코멘트