Created
June 28, 2024 05:23
-
-
Save bhuiyanmobasshir94/ccb243b0ad012daee0698c8d995677bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# Read the Excel file | |
df = pd.read_excel('/content/datadict_khaodao.xlsx') | |
# Group the DataFrame by column 'A' | |
grouped = df.groupby('table_nm') | |
# Create a new Excel writer object | |
with pd.ExcelWriter('/content/output_file.xlsx') as writer: | |
# Iterate over each group | |
for group_name, group_data in grouped: | |
# Write each group to a separate sheet | |
group_data.to_excel(writer, sheet_name=str(group_name), index=False) | |
print("Data has been successfully grouped and saved to 'output_file.xlsx'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment