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
#1
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:
img_path
title_1
desc_1
link_1


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'], 
            s_id=s_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)
            time.sleep(25) 
sample csv file:
Quote:img_path,desc_1 title_1,link_1
site.com/image22.jpg,someTitle,description1,site1.com
site.com/image32.jpg,someTitle,description2,site2.com
site.com/image44.jpg,someTitle,description3,site3.com

when I run this I get error on "return" I get:(unexpected indent).
I appreciate your help to make it work
Reply
#2
see this post I made earlier today: https://python-forum.io/Thread-MDB-to-CS...#pid133556
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Choices from .ods file columns cspower 3 518 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Create csv file with 4 columns for process mining thomaskissas33 3 691 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  How to check multiple columns value within range SamLiu 2 1,100 Mar-13-2023, 09:32 AM
Last Post: SamLiu
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,161 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 10,639 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Extracting Data into Columns using pdfplumber arvin 17 5,190 Dec-17-2022, 11:59 AM
Last Post: arvin
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,798 Dec-12-2022, 08:22 PM
Last Post: jh67
  deleting columns in CSV file astral_travel 8 2,161 Nov-26-2022, 09:36 PM
Last Post: astral_travel
  Replace columns indexes reading a XSLX file Larry1888 2 951 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  Load multiple Jason data in one Data Frame vijays3 6 1,499 Aug-12-2022, 05:17 PM
Last Post: vijays3

Forum Jump:

User Panel Messages

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