Untitled
unknown
plain_text
a month ago
1.1 kB
2
Indexable
Never
import pandas as pd def extract_emails(file_path, output_file, column_name='Email', emails_per_paragraph=25): # Load the Excel file df = pd.read_excel(file_path) # Extract the email column emails = df[column_name].dropna().tolist() # Split emails into paragraphs of 25 each paragraphs = [emails[i:i + emails_per_paragraph] for i in range(0, len(emails), emails_per_paragraph)] # Join the emails in each paragraph with commas email_paragraphs = ["\n".join([", ".join(paragraph)]) for paragraph in paragraphs] # Write the paragraphs to a text file with open(output_file, 'w') as f: for i, paragraph in enumerate(email_paragraphs): f.write(f"Paragraph {i+1}:\n{paragraph}\n\n") # Specify the Excel file path and the output txt file path file_path = 'path_to_your_excel_file.xlsx' output_file = 'output_emails.txt' # Adjust to your desired output file name # Call the function to extract emails and save to the file extract_emails(file_path, output_file) print(f"Emails have been saved to {output_file}")
Leave a Comment