From 30c35eefe6cee55b8eb9868164c7a683599e88c0 Mon Sep 17 00:00:00 2001 From: swetha-create-tech Date: Sun, 26 Oct 2025 12:40:54 +0530 Subject: [PATCH 1/2] Add files via upload --- typeconversion.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 typeconversion.py diff --git a/typeconversion.py b/typeconversion.py new file mode 100644 index 00000000..2c6a96a3 --- /dev/null +++ b/typeconversion.py @@ -0,0 +1,18 @@ +# Sno 3 : "Type Conversion and validation examples: Implement a Python program to type conversion and validation examples" + +#conversion of tuple to list +tuple=(1,2,3,4,5) +list1=list(tuple) +print("conversion of tuple to list",list1) +#conversion of int to float +a=22 +print("conversion of int to float",float(a)) +#conversion of float to int +b=33.0 +print("conversion of float to int",int(b)) +#int to string conversion +c=7888 +print("int to string conversion",str(c)) +#string len to float +s="swe" +print("string to float",float(len(s))) \ No newline at end of file From ca729b30026207aedbdcc64355b20b2bf76f07f8 Mon Sep 17 00:00:00 2001 From: swetha-create-tech Date: Fri, 31 Oct 2025 10:42:55 +0530 Subject: [PATCH 2/2] Add files via upload --- merge_csv_file.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 merge_csv_file.py diff --git a/merge_csv_file.py b/merge_csv_file.py new file mode 100644 index 00000000..dc08e088 --- /dev/null +++ b/merge_csv_file.py @@ -0,0 +1,78 @@ +# File: merge_csv_by_key.py +# Task: Merge multiple CSV files by a common key (e.g., "id") +# Author: VGLUG - Linus Torvalds - 2025 + +import pandas as pd +import glob +import os + +def merge_csv_files_by_key(folder_path, key_column, output_file): + # Find all CSV files in the given folder + csv_files = glob.glob(os.path.join(folder_path, "*.csv")) + + if not csv_files: + print("āŒ No CSV files found in the folder!") + return + + print(f"šŸ“‚ Found {len(csv_files)} CSV files. Merging by key '{key_column}'...") + + # Read the first CSV as base + merged_df = pd.read_csv(csv_files[0]) + print(f"āœ… Loaded: {os.path.basename(csv_files[0])}") + + # Merge all remaining CSV files one by one + for file in csv_files[1:]: + df = pd.read_csv(file) + print(f"šŸ”„ Merging: {os.path.basename(file)}") + merged_df = pd.merge(merged_df, df, on=key_column, how="outer") # or "inner" + + # Save the merged file + merged_df.to_csv(output_file, index=False) + print(f"\nāœ… Successfully merged files saved as: {output_file}") + +# ------------------ RUN SECTION ------------------ +if __name__ == "__main__": + folder = input("Enter the folder path containing CSV files: ").strip() + key = input("Enter the key column name to merge on (e.g., id): ").strip() + output = input("Enter output CSV file name (e.g., merged_output.csv): ").strip() + + merge_csv_files_by_key(folder, key, output) +# File: merge_csv_by_key.py +# Task: Merge multiple CSV files by a common key (e.g., "id") +# Author: VGLUG - Linus Torvalds - 2025 + +import pandas as pd +import glob +import os + +def merge_csv_files_by_key(folder_path, key_column, output_file): + # Find all CSV files in the given folder + csv_files = glob.glob(os.path.join(folder_path, "*.csv")) + + if not csv_files: + print("āŒ No CSV files found in the folder!") + return + + print(f"šŸ“‚ Found {len(csv_files)} CSV files. Merging by key '{key_column}'...") + + # Read the first CSV as base + merged_df = pd.read_csv(csv_files[0]) + print(f"āœ… Loaded: {os.path.basename(csv_files[0])}") + + # Merge all remaining CSV files one by one + for file in csv_files[1:]: + df = pd.read_csv(file) + print(f"šŸ”„ Merging: {os.path.basename(file)}") + merged_df = pd.merge(merged_df, df, on=key_column, how="outer") # or "inner" + + # Save the merged file + merged_df.to_csv(output_file, index=False) + print(f"\nāœ… Successfully merged files saved as: {output_file}") + +# ------------------ RUN SECTION ------------------ +if __name__ == "__main__": + folder = input("Enter the folder path containing CSV files: ").strip() + key = input("Enter the key column name to merge on (e.g., id): ").strip() + output = input("Enter output CSV file name (e.g., merged_output.csv): ").strip() + + merge_csv_files_by_key(folder, key, output)