import pandas as pd
import numpy as np
# Create sample DataFrame
df = pd.DataFrame({'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9]})
df1 = df + np.random.randn(3, 3)
mask = (df1 - df) > 0.5
# Apply styling and annotations to DataFrame
mask_idxs = []
# Add values from df1 as annotations in df
for i, j in zip(*np.where(mask)):
value = df1.iloc[i, j]
df.iloc[i, j] = f'{df.iloc[i, j]}/{value:.3f}'
mask_idxs.append((i+1, j+1))
print(mask_idxs)
正文完
发表至: Python
2023-11-26