I have 25 csv files with four columns each one and I have to compare 1 column named City
in all 25 CSVs, then write the output in csv as which city is present in how many files with file name.
e.g.
In excel I want New york in first 0 column first row and then in next column onward I want to get the file names where the city newyork is present. Like csv_output.csv
:
New york File 1, File 2, File 3, File 5, File 25
Jakarta File 1, File 7, File 19.
How to do it using Python, Pandas or CSV or any other option.
Currently I checked initially for two csv but that is not working too. My requirement is for 25 CSV files.
import pandas as pd
Data1 = pd.read_csv('C:/Users/File1.csv')
Data2 = pd.read_csv('C:/Users/File2.csv', usecols=['City'])
for df in [Data1, Data2]:
df['City'] = df['City'].str.rstrip()
result = pd.merge(netscan, computer, on='City', how='outer')
result.to_csv('Report.csv', index=False)
print(result)