Skip to content

Commit c8eafd5

Browse files
Update README.md
1 parent 31a89c0 commit c8eafd5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,25 @@ display(input_text, submit_btn, output_label)
322322
```python
323323
def save_dataframe(df, filename):
324324
"""
325-
Saves the given DataFrame to both CSV and Excel formats in the current working directory.
325+
Saves the given DataFrame to both CSV and Excel formats in the specified directory.
326326
327327
Args:
328328
df (pandas.DataFrame): The DataFrame to save.
329-
filename (str): The base filename without extension to use for saving the files.
329+
filename (str): The base filename with extension to use for saving the files.
330330
331331
Returns:
332332
None
333333
"""
334+
# Get the directory from the filename
335+
directory = os.path.dirname(filename)
336+
337+
# Check if the directory exists
338+
if not os.path.exists(directory):
339+
os.makedirs(directory)
340+
print(f"Directory created: {directory}")
341+
else:
342+
print(f"Directory already exists: {directory}")
343+
334344
# Define file paths
335345
csv_file = f"{filename}.csv"
336346
excel_file = f"{filename}.xlsx"

0 commit comments

Comments
 (0)