데이터 프레임이 있으며 다음과 같은 특성이 있습니다. id, text, created_at, retweet_count, favorite_count, source, user_id데이터 프레임에서 특정 열을 제거하는 방법
"RT"로 시작하는 df.text 행을 추출하여 새 데이터 프레임을 가져오고 싶습니다.
non_retweeted_list = []
for i in range(len(df)):
if (df.text[i][0] and df.text[i][1]) == ('R' and 'T'):
pass
else:
non_retweeted_list.append(df[i])
하지만 KeyError를 아래 얻을 :
는내가 그것을 어떻게
KeyError
Traceback (most recent call last)
/home/bd/anaconda3/lib/python3.5/site-packages/pandas/indexes
/base.py in get_loc(self, key, method, tolerance)
1944 try:
-> 1945 return self._engine.get_loc(key)
1946 except KeyError:
.
.
.
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-3-5dfc6d77a22c> in <module>()
5 pass
6 else:
----> 7 non_retweeted_list.append(df[i])
.
.
.
KeyError: 0
을 를 해결할 수 ?
아마도 색인 생성 오류입니다. 데이터 프레임의 일부를 공유하십시오. 또한,'type (df.index [0])'을 할 때 무엇을 얻는가? –
또한'df.text'를'df [ 'text']'로 변경하십시오 : https://stackoverflow.com/a/42978728/2539738 –