Я проверил, что столбцы, показывающие типы данных минус процент, одинаковы в обоих источниках. p>
Может ли кто-нибудь помочь мне выяснить, почему?
Код: Выделить всё
# Define the columns you want to process
columns = ['a', 'b', 'c', 'd']
# Create the results DataFrame
results_df = pd.DataFrame()
results_df['date'] = c_df['date']
results_df['id'] = c_df['id']
for col in columns:
# calculating the absolute difference
diff = np.abs(c_df[f'{col}_s1'] - c_df[f'{col}_s2'])
# calculating mean for snowflake columns
norm_diff = c_df[f'{col}_s1'].mean()
# Avoid division by zero
if norm_diff == 0:
percentage = np.zeros(len(diff))
else:
# calculating percentage difference b/w the columns in both datasets
percentage = (diff / norm_diff) * 100
# Round the percentage_difference and add % symbol
results_df[col] = [f"{round(diff)}%" for diff in percentage]
display(results_df)
a
b
c
d
0%
5%
10%
-5%
10%
100%
-50%
200%
Подробнее здесь: https://stackoverflow.com/questions/785 ... ercentages
Мобильная версия