Here's a Python script to remove '- ' and replace it with a space in the 'name' column of a CSV file:

import csv

# Open the CSV file
with open('input.csv', 'r') as infile, open('output.csv', 'w', newline='') as outfile:
    reader = csv.reader(infile)
    writer = csv.writer(outfile)

    # Loop through each row in the CSV file
    for row in reader:
        # Replace '- ' with space in the name column
        row[0] = row[0].replace('- ', ' ')
        # Write the modified row to the output CSV file
        writer.writerow(row)

This script opens the input CSV file and creates a new output CSV file. It then uses the csv.reader and csv.writer to read and write rows in the CSV file.

For each row, it replaces '- ' with a space in the first (name) column using the replace method. Finally, it writes the modified row to the output CSV file using the writer.writerow method.

You can adjust the input and output file paths as needed for your specific use case.

Python Script: Remove Hyphens and Replace with Spaces in CSV Names

原文地址: https://www.cveoy.top/t/topic/nTJW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录