Exel : IndexError: At least one sheet must be visible

Hello everyone,

I've been grappling with a coding challenge for several hours, and I could use some assistance.

I've been working on a script designed to read an Excel file with multiple sheets. Everything was functioning correctly until yesterday. Suddenly, I encountered two issues: firstly, I'm unable to open the Excel file within my IDE, and secondly, when attempting to print the new data to a new Excel file with multiple sheets, it creates a corrupted Excel file.

I've been troubleshooting this problem since yesterday, and despite downloading openpyxl and all the necessary modules, I haven't been able to find a solution. If anyone could lend a hand, I would greatly appreciate it.

here is the code: 

import numpy as np
import pandas as pd
import matplotlib.pylab as plt
from matplotlib.pyplot import figure

# Read Excel file with multiple sheets
excel_file_path = '/Users/guylevkovich/PycharmProjects/pythonProject1/9_13_8_23.xlsx'
xls = pd.ExcelFile(excel_file_path)

# Create an empty DataFrame to store the combined data
combined_df = pd.DataFrame()

# Loop through
# each sheet in the input Excel file

with pd.ExcelWriter('/Users/guylevkovich/PycharmProjects/pythonProject1/book.xlsx') as writer:
    for sheet_name in xls.sheet_names:
        # Read the current sheet into a DataFrame
        df = pd.read_excel(xls, sheet_name)

        drop_col =df.drop('min', inplace=False, axis=1)

        df2= fil_df_h.groupby('hen').sum()

        df3.to_excel(writer, sheet_name='Sheet_' + sheet_name)
        combined_df = pd.concat([combined_df, df3])
        # print(combined_df)

# Write the combined DataFrame to a new sheet in the output Excel file
combined_df.to_excel('/Users/guylevkovich/PycharmProjects/pythonProject1/output_combined.xlsx', sheet_name='Combined_Sheet' ,index=False)
# sort_values=sorted_read.to_string(index=None)

figure(num=None, figsize=(16, 6))
font: dict[str, str | int] = {'family': 'Times New Roman',
        'weight': 'bold',
        'size': 12}
# plt.style.use('_mpl-gallery')

# ['Solarize_Light2', '_classic_test_patch',
#  '_mpl-gallery', '_mpl-gallery-nogrid', 'bmh', 'classic',
#  'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale',
#  'seaborn-v0_8', 'seaborn-v0_8-bright', 'seaborn-v0_8-colorblind',
#  'seaborn-v0_8-dark', 'seaborn-v0_8-dark-palette', 'seaborn-v0_8-darkgrid',
#  'seaborn-v0_8-deep',
#  'seaborn-v0_8-muted', 'seaborn-v0_8-notebook',
#  'seaborn-v0_8-paper', 'seaborn-v0_8-pastel', 'seaborn-v0_8-poster',
#  'seaborn-v0_8-talk', 'seaborn-v0_8-ticks', 'seaborn-v0_8-white', 'seaborn-v0_8-whitegrid',
#  'tableau-colorblind10']

# t
plt.subplot(1, 2, 1)
plt.hist(sorted_read, color='g',bins=20,alpha=0.4)

ax = plt.gca()
# ax.spines['bottom'].set_visible(False)
# ax.spines['left'].set_visible(False)

plt.xlabel('frequent Eating ')
# #
# #
# #


Please sign in to leave a comment.