Untitled
unknown
plain_text
a year ago
852 B
11
Indexable
import pandas as pd
def combine_csv_remove_duplicates(file1, file2, output_file):
"""
Combines two CSV files, removes duplicate rows, and writes the result to a new file.
:param file1: Path to the first CSV file.
:param file2: Path to the second CSV file.
:param output_file: Path to the output CSV file.
"""
# Load both CSV files into dataframes
df1 = pd.read_csv(file1)
df2 = pd.read_csv(file2)
# Concatenate the dataframes
combined_df = pd.concat([df1, df2], ignore_index=True)
# Remove duplicates based on all columns
combined_df = combined_df.drop_duplicates()
# Write to output CSV
combined_df.to_csv(output_file, index=False)
# Example usage
file1 = 'file1.csv'
file2 = 'file2.csv'
output_file = 'combined_output.csv'
combine_csv_remove_duplicates(file1, file2, output_file)
Editor is loading...
Leave a Comment