I tried writing code in jupyter notebook saved as vookup.py in user folder and run the script in
anacondas prompt.cd command to use folder and then python vlookup.py.
but no output.I am new to .py,help me
import pandas as pd
def vlooup(input_file, common_column, lookup_columns):
# Read input file
input_df = pd.read_csv(input_file)
# Ask for file paths to lookup
file_paths = {}
for column in lookup_columns:
file_paths[column] = input(f"Enter the file path for column '{column}': ")
# Perform lookup
result = {}
for index, row in input_df.iterrows():
common_value = row[common_column]
result[common_value] = {}
for column, file_path in file_paths.items():
lookup_df = pd.read_csv(file_path)
if common_value in lookup_df[common_column].values:
result[common_value][column] = lookup_df.loc[lookup_df[common_column] == common_value]
else:
result[common_value][column] = f"No matching value found in {column}"
return result
if __name__ == "__main__":
input_file = input("Enter the path to the input file: ")
common_column = input("Enter the name of the common column: ")
lookup_columns = input("Enter the names of the columns to lookup (separated by comma): ").split(',')
result = lookup_files(input_file, common_column, lookup_columns)
print(result)
run the python vlooup.py