Filter excel based on color of cell
import numpy as np
import pandas as pd
from StyleFrame import StyleFrame, utils
sf = StyleFrame.read_excel('.\\el_data\\sample_name.xlsx', read_style=True, use_openpyxl_styles=False)
def only_cells_with_red_text(cell):
return cell if cell.style.font_color in {utils.colors.red, 'FFFF0000'} else np.nan
sf_1 = sf[['OLD_DOB']]
sf_2 = StyleFrame(sf_1.applymap(only_cells_with_red_text).dropna(axis=(0, 1), how='all'))
df=pd.DataFrame(sf.data_df)
df_2=df.iloc[sf_2.index]
print(df_2)
import pandas as pd
from StyleFrame import StyleFrame, utils
sf = StyleFrame.read_excel('.\\el_data\\sample_name.xlsx', read_style=True, use_openpyxl_styles=False)
def only_cells_with_red_text(cell):
return cell if cell.style.font_color in {utils.colors.red, 'FFFF0000'} else np.nan
sf_1 = sf[['OLD_DOB']]
sf_2 = StyleFrame(sf_1.applymap(only_cells_with_red_text).dropna(axis=(0, 1), how='all'))
df=pd.DataFrame(sf.data_df)
df_2=df.iloc[sf_2.index]
print(df_2)
Comments
Post a Comment