Skip to content

Instantly share code, notes, and snippets.

@bhuiyanmobasshir94
Created June 28, 2024 05:23
Show Gist options
  • Save bhuiyanmobasshir94/ccb243b0ad012daee0698c8d995677bb to your computer and use it in GitHub Desktop.
Save bhuiyanmobasshir94/ccb243b0ad012daee0698c8d995677bb to your computer and use it in GitHub Desktop.
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