I’m working on a file related task..I have a CSV file with some rows and headers..I need to fetch column with particular header and create a new column at the end and do some operations..how can i fetch column values which is having particular header value and how can i create new column in the end?
Share
Assuming you have CSV in following format
Zipcode Network ID Network Name Zone New Network? Display Name
64024 275 Kansas City 2 No Kansas City
64034 275 Kansas City 2 No Kansas City
You can user FasterCSV;
If you have headers in your csv then you can specify it
headers => truewhat you can do is to fetch data from row by row using FasterCSV,as given belowEach time you iterate the csv you would get row from your CSV file, now you already know that column 2 has “network_id” header and column 3 has “network name” header so you can easily give
network_id = row[2],network_name = row[3]hope it would answer your question