이 코드는 계수를 가져 와서이를 사용하여 아래 DF를 수정합니다. 그것은 scaling()이고 잘 동작하는 또 다른 함수를 사용합니다. 나는 그것이 최종 결과를 인쇄 할 수 있다면 일단이 코드는 new_df가 그 성공적으로 수행하지만 나에게 new_df를 반환 실패하고 다음 오류가 발생, 실행 :UnboundLocalError : 할당 전에 로컬 변수 'graph_df'가 참조되었습니다.
def scale_for_all_companies(coefficient, delta, company_name, company_code, start_date, end_date):
scaling_dict = scaling(normalised_graph_points_on_xaxis(company_name, company_code, start_date, end_date),
coefficient, delta, company_name)
print(scaling_dict)
sub_mse = scaling_dict.get('Sub_MSE')
add_mse = scaling_dict.get('Add_MSE')
if delta > 0.0001:
if abs(add_mse-sub_mse) > 0.05:
if add_mse > sub_mse:
coefficient = coefficient + delta
scale_for_all_companies(coefficient, delta, company_name, company_code, start_date, end_date)
elif add_mse < sub_mse:
coefficient = coefficient - delta
scale_for_all_companies(coefficient, delta, company_name, company_code, start_date, end_date)
else:
delta = delta/2
scale_for_all_companies(coefficient, delta, company_name, company_code, start_date, end_date)
else:
new_coefficient = coefficient
print('Co-efficient:', new_coefficient)
graph_df = normalised_graph_points_on_xaxis(company_name, company_code, start_date, end_date)
print(graph_df)
for index, row in graph_df.iterrows():
new_df = graph_df
graph_df.set_value(index, twitter_sentiment, row[twitter_sentiment] * coefficient)
return new_df
오류를
File "/Users/Pankaj/PycharmProjects/untitled/scaling_sentiment_graph.py", line 52, in scale_for_all_companies
scale_for_all_companies(coefficient, delta, company_name, company_code, start_date, end_date)
File "/Users/Pankaj/PycharmProjects/untitled/scaling_sentiment_graph.py", line 67, in scale_for_all_companies
return graph_df
UnboundLocalError: local variable 'graph_df' referenced before assignment
나는 이와 비슷한 게시물을 본 적이 있지만 어느 누구도이 특별한 경우를 충족시키지 못합니다. 도와주세요! 고맙습니다.
'delta> 0.0001 :'가'True'이면,'new_df'가 존재하지 않으므로'return' 할 수 없습니다. – roganjosh
죄송합니다. 오류는'UnboundLocalError : 할당 전의 로컬 변수 'new_df'입니다. –
그리고 함수에서 전달한 첫 번째 델타는 0.001보다 큰 0.001이지만 프로그램 전체에서 델타는 계속 감소합니다. –