Python Forum
How to fill parameter with data from multiple columns CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fill parameter with data from multiple columns CSV file
I am new to Python, I want to make a function work using data from multiple columns CSV files, one row by one row with some delay in between each run.

This is want to achieve:

1- Read from first CSV file within a range ( e.g. row 0 to row 3)
2- Use cell data of one row, to fill the right parameter area in the function, and run the function, some delay, then it goes to the next row, and run,
3- Some delay again, then it goes to next CSV file, do the same, until the last CSV file.

I have the tried the following code, but it does not work.
The following code works fine with one column CSV file, but using data from multiple columns, I am not sure how to pass the right data to the right parameter inside the function.

there are 4 parameters that I want to get the value from csv file from the column with the same header name:

from abc.zzz  import xyz
path_id_map = [
    {'path':'file1.csv', 'id': '12345678'},
    {'path':'file2.csv', 'id': '44556677'}
    {'path':'file3.csv', 'id': '33377799'}
    {'path':'file4.csv', 'id': '66221144'}]
s_id = None
for pair in path_id_map:
    with open(pair['path'], 'r') as f:
        for i in range(0, 3):      
            zzz.func1(img_path=f.readline().rstrip(','), title_1=f.readline().rstrip(','), 
            desc_1=f.readline().rstrip(','), link_1=f.readline().rstrip(','), B_id=pair['id'], 
            return zzz.func1(img_file=img_path, title_1=title_1, desc_1=desc_1, 
                 link_1=link_1, B_id=B_id, s_id=s_id)
sample csv file:
Quote:img_path,desc_1 title_1,link_1,someTitle,description1,,someTitle,description2,,someTitle,description3,

when I run this I get error on "return" I get:(unexpected indent).
I appreciate your help to make it work
see this post I made earlier today:

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split single column to multiple columns SriRajesh 1 132 Jan-07-2022, 06:43 PM
Last Post: jefsummers
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 324 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  How to map two data frames based on multiple condition SriRajesh 0 291 Oct-27-2021, 02:43 PM
Last Post: SriRajesh
  rows from sql query need to write to a file as columns sjcsvatt 6 622 Oct-09-2021, 12:45 AM
Last Post: snippsat
  [SOLVED] Input parameter: Single file or glob? Winfried 0 456 Sep-10-2021, 11:54 AM
Last Post: Winfried
  Apply fillna to multiple columns in dataframe rraillon 2 646 Aug-05-2021, 01:11 PM
Last Post: rraillon
  Python Pandas: How do I average ONLY the data >1000 from several columns? JaneTan 0 621 Jul-17-2021, 01:34 PM
Last Post: JaneTan
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 774 Jul-02-2021, 02:19 PM
Last Post: xtc14
  [Solved] Using readlines to read data file and sum columns Laplace12 4 962 Jun-16-2021, 12:46 PM
Last Post: Laplace12
  Load the data from multiple source files to one table amy83 2 1,058 Apr-27-2021, 12:33 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020