import streamlit as st import pandas as pd # Inject custom CSS to style the buttons st.markdown(""" """, unsafe_allow_html=True) def excel_page(): st.title(":green[Excel Data Format]") # Section 1: What is Excel? st.subheader("1. What is Excel?") st.write(""" Excel is a spreadsheet tool for storing data in tabular format with rows and columns. The data can be in various forms such as numeric values, text, dates, etc. Excel files are commonly saved with `.xls` or `.xlsx` file extensions. They are widely used in businesses for data analysis, reporting, and visualization. """) # Section 2: How to Read Excel Files st.subheader("2. How to Read Excel Files") st.write(""" To read Excel files in Python, the `pandas` library is commonly used. You can use `pd.read_excel()` function to load the Excel file into a DataFrame. """) st.code(""" import pandas as pd # Read an Excel file df = pd.read_excel('data.xlsx', sheet_name='Sheet1') # Display the data print(df) """, language='python') # Section 3: Issues Encountered st.subheader("3. Issues Encountered When Handling Excel Files") st.write(""" - **File not found**: If the file path is incorrect or the file does not exist. - **Sheet not found**: If the sheet name specified in `sheet_name` doesn't exist. - **Missing Libraries**: Sometimes, the necessary libraries for reading `.xlsx` files, such as `openpyxl` or `xlrd`, may be missing. """) # Section 4: How to Overcome These Errors/Issues st.subheader("4. How to Overcome These Errors/Issues") st.write(""" - **File not found**: Make sure the file path is correct. - **Sheet not found**: Verify the sheet name or list all sheet names using `pd.ExcelFile('data.xlsx').sheet_names`. - **Missing Libraries**: Ensure all necessary libraries are installed using pip: ```bash pip install openpyxl xlrd ``` - **Handle Missing File Error**: Catch errors using `try` and `except` block. """) st.code(""" # Handling File Not Found Error try: df = pd.read_excel('data.xlsx', sheet_name='Sheet1') except FileNotFoundError: print("File not found. Check the file path.") # List available sheet names excel_file = pd.ExcelFile('data.xlsx') print(excel_file.sheet_names) """, language='python') # Section 5: Downloadable Jupyter Notebook/PDF st.write("### Download the Code Example as a Jupyter Notebook or PDF") # Create a sample Jupyter notebook for download (for now, it's a basic example) notebook_content = """ # Excel Handling in Python ## What is Excel? Excel is a spreadsheet tool for storing data in tabular format with rows and columns... ## How to Read Excel Files ```python import pandas as pd df = pd.read_excel('data.xlsx', sheet_name='Sheet1') print(df)