I am trying to fetch data from one CSV file and put the respective information of that data which is in another CSV file and merge them in a Output file.
lets say this is my lookup file:
Name.csv:
+------+
|CI_Name|
+------+
| a |
| b |
| c |
| ... |
+------+
This is another csv file from where I will get the related information of the server, Ip address, etc
Main.csv
+------+--------+------------+
|CI_Name | Server | IP-Address |
+------+--------+------------+
| a | | |
| b | | |
| c | | |
| ... | | |
+------+--------+------------+
What I want is to merge this two information into a new excel sheet(csv), basically a VLOOKUP, Please help Python Coders! I need a code and explanation, so that I will be able to do Vlookup in future with ease.
This is the code that I have tried:
import csv
with open('Name.csv', 'r') as csvinput:
with open('Main.csv', 'r') as lookuplist:
with open('Output.csv', 'w') as output:
reader = csv.reader(lookuplist)
reader1 = csv.reader(csvinput)
writer = csv.writer(output)
for CI_Name in reader1:
for SERVER, FQDN, AUTOMATION_ADMINISTRATOR, IP_ADDRESS, PRIMARY1, MHT_1, MHT_2, MHT_3, MHT_4 in reader: #this are the columnss i need to match from the Main and import it to the output.csv
if CI_Name[0] == FQDN[0]:
CI_Name.append(FQDN[1:])
writer.writerow(CI_Name)
The Error that I'm getting is:
for SERVER, FQDN, AUTOMATION_ADMINISTRATOR, IP_ADDRESS, PRIMARY1, MHT_1, MHT_2, MHT_3, MHT_4 in reader:
ValueError: too many values to unpack