import numpy as np import pandas as pd from statsmodels.stats.anova import anova_lm from statsmodels.formula.api import ols from scipy.stats import stats from tools.algo.humidity import absolute_humidity from tools.algo.interpolation import interpolate_value from datetime import datetime import plotly.express as px if __name__ == "__main__": df_weather = pd.read_csv("/home/juni/PycharmProjects/failure_analysis/data/weather/202007010000_202308310000_f.csv") df_failure = pd.read_excel("/home/juni/PycharmProjects/failure_analysis/data/failure/대옹 작업내용.xlsx") times = df_failure["작업 시작 시간"] temp = [] humidity = [] for time in times: temp.append(interpolate_value(df_weather, timestamp=time, col_key="기온", k=6)) humidity.append(interpolate_value(df_weather, timestamp=time, col_key="상대습도", k=6)) absolute_humidity = absolute_humidity(humidity, temp) df_failure["기온"] = temp df_failure["상대습도"] = humidity df_failure["절대습도"] = absolute_humidity df_failure['불량 여부'] = np.where(df_failure['불량 여부'] == 'F', 0, df_failure['불량 여부']) df_failure['불량 여부'] = np.where(df_failure['불량 여부'] == 'T', 1, df_failure['불량 여부']) df_failure = df_failure.loc[:,['불량 여부', '상대습도', '기온', '절대습도']] F_statistic, pVal = stats.f_oneway(df_failure[df_failure["불량 여부"] == 0].loc[:,['상대습도', '기온', '절대습도']], df_failure[df_failure["불량 여부"] == 1].loc[:,['상대습도', '기온', '절대습도']]) fig_df = pd.DataFrame(np.transpose([F_statistic, pVal]), index=['상대습도', '기온', '절대습도'], columns=["F_", "pVal"]) fig = px.scatter(fig_df) fig.add_hline(y=0.05, line_dash="dash", line_color="red") fig.show() print(fig_df)