Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use csv column as function arguments

csv

name;subnet
name_a;192.168.111.0/24
name_b;192.168.168.0/24
name_c;192.168.29.0/24

I try to run a function with a for loop for every column from a csv by passing the column values to function arguments. How should I do this?

I’m not sure if I have to import the csv content to a list, dict or if it is possible to directly use the columns as function arguments.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

with open(csv_address_objects, mode='r', encoding='utf-8-sig') as csv_file:
    csv_reader = csv.DictReader(csv_file, delimiter=';')
    list_of_csv = dict(csv_reader)

>Solution :

Try this:

import pandas as pd

data = pd.read_csv("test.csv", sep=";")

name = data["name"].to_list()
subnet = data["subnet"].to_list()

def process_data(name, subnet):
    # do stuff
    pass
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading