首页 > 解决方案 > Python Change theColor of Column in a Dataframe then merge the Frame

问题描述

I have multiple Data Frames lets say; | Date | Name | Value | |:---- |:------:| -----:| |01.01 | A | 20 | |02.01 | B | Null | |03.01 | C | 10 | and | Date | Name | Value_2 | |:---- |:------:| -------:| |01.01 | A | 20 | |02.01 | B | 10 | |03.01 | C | 10 |

I want to make Value_2 column red then merge these table as | Date | Name | Value |Value_2 | |:---- |:------:| -----:|-------:| |01.01 | A | 20 | 10 | |02.01 | B | Null | 10 | |03.01 | C | 10 | 10 | and then change the null value with value2

Without formatting my codes works perfectly, but if change the value2_2 column name with

''' col_ref = {'value': 'color: red'}

df=df.style.apply(lambda x: pd.DataFrame(col_ref, index=df.index, columns=df.columns).fillna(''),axis=None) '''

I cant do merging or dropping. I know after using style it is no more Dataframe so I can't do these operation. But is there any other way to this process. The reason is to save the final form to excel and be able to see where these data coming from (value or value_2)

标签: pythonpandasdataframeformatting

解决方案


推荐阅读