Advertisement
Python253

create_example_csv

Mar 12th, 2024
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: create_example_csv.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6. # For use with 'parity_number_counter.py': https://pastebin.com/KcCdq19X
  7.  
  8. """
  9. Description:
  10. This script creates an example CSV file ('example.csv') with sample data.
  11.  
  12. Requirements:
  13. - Python 3.x
  14.  
  15. Usage:
  16. 1. Save this script as 'create_example_csv.py'.
  17. 2. Run the script.
  18.  
  19. Note: Adjust the 'example_filename' variable in the script as needed.
  20. """
  21. import csv
  22.  
  23. def create_example_csv(filename):
  24.     # Define the data to be written to the CSV file
  25.     data = [
  26.         ['Name', 'Age', 'City', 'Salary', 'Experience Years', 'Height (cm)', 'Weight (kg)', 'Savings', 'Days of Vacation', 'Average Speed (kmph)'],
  27.         ['John Doe', 30, 'New York', 75000.50, 5, 180, 75.5, 120000.75, 20, 45.5],
  28.         ['Jane Smith', 25, 'Los Angeles', 65000.75, 3, 165, 60.2, 95000.20, 15, 40.0],
  29.         # Add more data as needed
  30.     ]
  31.  
  32.     # Write data to the CSV file
  33.     with open(filename, 'w', newline='') as csvfile:
  34.         csvwriter = csv.writer(csvfile)
  35.         csvwriter.writerows(data)
  36.  
  37. if __name__ == "__main__":
  38.     # Set the filename for the example CSV file
  39.     example_filename = 'example.csv'
  40.  
  41.     # Create the example CSV file in the current working directory
  42.     create_example_csv(example_filename)
  43.  
  44.     print(f"Example CSV file '{example_filename}' created in the current working directory.")
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement