Update excel_handling_guide.ipynb
Browse files- excel_handling_guide.ipynb +0 -90
excel_handling_guide.ipynb
CHANGED
@@ -1,91 +1 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
|
4 |
-
# Inject custom CSS to style the buttons
|
5 |
-
st.markdown("""
|
6 |
-
<style>
|
7 |
-
.stButton>button {
|
8 |
-
background-color: #4CAF50;
|
9 |
-
color: white;
|
10 |
-
width: 100%;
|
11 |
-
}
|
12 |
-
</style>
|
13 |
-
""", unsafe_allow_html=True)
|
14 |
-
|
15 |
-
def excel_page():
|
16 |
-
st.title(":green[Excel Data Format]")
|
17 |
-
|
18 |
-
# Section 1: What is Excel?
|
19 |
-
st.subheader("1. What is Excel?")
|
20 |
-
st.write("""
|
21 |
-
Excel is a spreadsheet tool for storing data in tabular format with rows and columns.
|
22 |
-
The data can be in various forms such as numeric values, text, dates, etc.
|
23 |
-
Excel files are commonly saved with `.xls` or `.xlsx` file extensions.
|
24 |
-
They are widely used in businesses for data analysis, reporting, and visualization.
|
25 |
-
""")
|
26 |
-
|
27 |
-
# Section 2: How to Read Excel Files
|
28 |
-
st.subheader("2. How to Read Excel Files")
|
29 |
-
st.write("""
|
30 |
-
To read Excel files in Python, the `pandas` library is commonly used.
|
31 |
-
You can use `pd.read_excel()` function to load the Excel file into a DataFrame.
|
32 |
-
""")
|
33 |
-
|
34 |
-
st.code("""
|
35 |
-
import pandas as pd
|
36 |
-
|
37 |
-
# Read an Excel file
|
38 |
-
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
|
39 |
-
|
40 |
-
# Display the data
|
41 |
-
print(df)
|
42 |
-
""", language='python')
|
43 |
-
|
44 |
-
# Section 3: Issues Encountered
|
45 |
-
st.subheader("3. Issues Encountered When Handling Excel Files")
|
46 |
-
st.write("""
|
47 |
-
- **File not found**: If the file path is incorrect or the file does not exist.
|
48 |
-
- **Sheet not found**: If the sheet name specified in `sheet_name` doesn't exist.
|
49 |
-
- **Missing Libraries**: Sometimes, the necessary libraries for reading `.xlsx` files, such as `openpyxl` or `xlrd`, may be missing.
|
50 |
-
""")
|
51 |
-
|
52 |
-
# Section 4: How to Overcome These Errors/Issues
|
53 |
-
st.subheader("4. How to Overcome These Errors/Issues")
|
54 |
-
st.write("""
|
55 |
-
- **File not found**: Make sure the file path is correct.
|
56 |
-
- **Sheet not found**: Verify the sheet name or list all sheet names using `pd.ExcelFile('data.xlsx').sheet_names`.
|
57 |
-
- **Missing Libraries**: Ensure all necessary libraries are installed using pip:
|
58 |
-
```bash
|
59 |
-
pip install openpyxl xlrd
|
60 |
-
```
|
61 |
-
- **Handle Missing File Error**: Catch errors using `try` and `except` block.
|
62 |
-
""")
|
63 |
-
|
64 |
-
st.code("""
|
65 |
-
# Handling File Not Found Error
|
66 |
-
try:
|
67 |
-
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
|
68 |
-
except FileNotFoundError:
|
69 |
-
print("File not found. Check the file path.")
|
70 |
-
|
71 |
-
# List available sheet names
|
72 |
-
excel_file = pd.ExcelFile('data.xlsx')
|
73 |
-
print(excel_file.sheet_names)
|
74 |
-
""", language='python')
|
75 |
-
|
76 |
-
# Section 5: Downloadable Jupyter Notebook/PDF
|
77 |
-
st.write("### Download the Code Example as a Jupyter Notebook or PDF")
|
78 |
-
|
79 |
-
# Create a sample Jupyter notebook for download (for now, it's a basic example)
|
80 |
-
notebook_content = """
|
81 |
-
# Excel Handling in Python
|
82 |
-
|
83 |
-
## What is Excel?
|
84 |
-
Excel is a spreadsheet tool for storing data in tabular format with rows and columns...
|
85 |
-
|
86 |
-
## How to Read Excel Files
|
87 |
-
```python
|
88 |
-
import pandas as pd
|
89 |
-
|
90 |
-
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
|
91 |
-
print(df)
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|