• 카테고리

    질문 & 답변
  • 세부 분야

    데이터 분석

  • 해결 여부

    미해결

오류 질문

21.01.12 10:59 작성 조회수 182

0

import pandas as pd

df_amount = pd.read_csv("amount_per_year.csv")
df_employee = pd.read_csv("employee_list.csv")
df_merged = pd.merge(df_amount, df_employee, on='id')
#print(df_merged)

df_count = df_merged[(df_merged['amount']>=10) \
                     & (df_merged['year'] == 2020)]
#print(df_count)

df_count['output'] = df_count['amount'] / df_count['salary']
df_count = df_count.sort_values(['output'])
print(df_count)

위와 같이 코드를 짜니 아래와 같은 오류가 떴습니다. 문제가 뭐였을까요?

C:/Users/equal/PycharmProjects/pandas_practice/merge_exercise/01-2 merge_exercise.py:12: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df_count['output'] = df_count['amount'] / df_count['salary']

답변 2

·

답변을 작성해보세요.

1

 df_count['output'] = df_count['amount'] / df_count['salary']
위와 같이 연산 하는 경우 값이 복사되어서 연산을 하기 때문에 속도가 느려질 수 있어서 나오는 경고 입니다.
.loc를 이용할 것을 권장하는 메세지 입니다.

0

김보준님의 프로필

김보준

질문자

2021.01.12

답변 감사합니다:)