I am coding a school project rn, where I have to analyse stocks and predict them. So now my problem is the code is finished, but I want to add colours in my Excel file.
I am using the following libraries:
- requests
- bs4
- pandas
- datetime
So I looked up the whole Internet and found nothing helpful. This is my code where the Excel file is written:
def write_xlsx(): help = [] for i in range(len(new_price)): list = [] list.append(new_price[i]) list.append(price_dif[i]) list.append(high[i]) list.append(low[i]) list.append(keepsell[i]) help.append(list) list = [datetime.now(), None, None, None, None] help.append(list) df1 = pd.DataFrame(help, index=[get_names()], columns=['Price (€)', 'Difference (€)', 'High (€)', 'Low (€)', 'Prediction']) try: df1.to_excel("Stock.xlsx", sheet_name='Stonks') except: print("Please close the Exel Document within 15 seconds!") time.sleep(15) df1.to_excel("Stock.xlsx", sheet_name='Stonks')
I want to color my Price Differences or the High|Low column. Can you please help me how to color the Excel file.
If you need more code let me know.
Advertisement
Answer
See these posts in the Stack Overflow:
Reference-1: Coloring Cells in Pandas
Reference-2: Easiest way to create a color gradient on excel using python/pandas?