본문 바로가기

python5

[ Pandas ] Dataframe 필요한 열(column) 추출 import pandas as pd data = { 'A':[1,2,3,4,5], 'B':['a','b','c','d','e'], 'C':['apple','banana','grape','strawberry','peach'] } df = pd.DataFrame(data) 1. 컬럼명 사용 df[['A', 'B']] 2. iloc 사용 # 0번째, 2번째 컬럼의 모든행 df.iloc[:, [0,2]] 3. drop 사용 : drop은 컬럼 제거할 때 사용하는 방법이지만 추출할때도 사용 가능. (원하는 컬럼 제외하고 나머지를 제거) # 'A', 'C' 추출 df.drop(['B', 'D'], axis=1) axis = 0 : 행을 제거 / axis = 1 : 열을 제거 2023. 5. 7.
[Python] Dataframe_image OsError: Chrome executable not able to be found on your machine 원인 파이썬에서 dataframe_image 사용시 크롬 설치가 안됐을때 뜨는 에러 해결 apt install chromium-chromedriver 2023. 5. 7.
[Python] Append Row to pandas DataFrame # Append Row to DataFrame list_row = ["Hyperion", 27000, "60days", 2000] df.loc[len(df)] = list_row # Insert Dict to the dataframe using DataFrame.append() new_row = {'Courses':'Hyperion', 'Fee':24000, 'Duration':'55days', 'Discount':1800} df2 = df.append(new_row, ignore_index=True) # Append new row to specifig index name df2 = df.append(pd.DataFrame([new_row],index=['7'],columns=df.columns)) # .. 2022. 12. 12.
[Python] AttributeError: 'DataFrame' object has no attribute 'tolist' 데이터 프레임을 리스트로 변경할때 뜨는 에러 메세지 df[col].tolist() # AttributeError: 'DataFrame' object has no attribute 'tolist' 해결방법 df[col].values.tolist() values.tolist() 로 변경하면 된다. 2022. 12. 12.
반응형