Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

CSV COLUMN READER

I have a CSV file that looks like this:

htt ps://gyazo. c om/51b69c4d128286521e86cb5715b5fd9a

I need a program that does this:

If Title = 'Title 1(2, 3, 4)' Data should = '1'("Live", 3.6)

The program basically needs to check that each column holds the correct data type.

I have tried to do this loads of way but everything seems to work with rows not columns and it is confusing me.

Thanks a lot guys
Stick to one thread please, you've created at least three.
(Mar 7, 2017 07:43 AM)(╯°□°)╯︵ ┻━━┻ Wrote:  Stick to one thread please, you've created at least three.

Yeah sorry I am stressing out. This needs to be done.
Is there any reason why you can't use Excel to do this?
It's not quick enough and can only be used on machines with excel
Code
import sys, csv

with open('file.csv', 'rb') as csvfile:

    # get number of columns
    for line in csvfile.readlines():
        array = line.split(' ')
        first_item = array[0]

    num_columns = len(array)
    csvfile.seek(0)

    reader = csv.reader(csvfile)
    included_cols = [1,2,3,4]

    for row in reader:
             content=list(row[i] for i in included_cols)
             if 'blah blah' not in content:
                newdata=content
                print newdata

Here is an example code for csv .. see the row part? just change it to whatever you need it to do ..
[Image: V9Gredc.png]
(Mar 7, 2017 10:01 AM)Malicious Intent Wrote:  
Code
import sys, csv

with open('file.csv', 'rb') as csvfile:

    # get number of columns
    for line in csvfile.readlines():
        array = line.split(' ')
        first_item = array[0]

    num_columns = len(array)
    csvfile.seek(0)

    reader = csv.reader(csvfile)
    included_cols = [1,2,3,4]

    for row in reader:
             content=list(row[i] for i in included_cols)
             if 'blah blah' not in content:
                newdata=content
                print newdata

Here is an example code for csv .. see the row part? just change it to whatever you need it to do ..

Very helpful comment thank you


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by GuillyianJul 11, 2022 05:19 AM 5 233 Jul 11, 2022 05:19 AM
Last Post: MavenGradle
[.NET] by QU35TFeb 10, 2022 10:19 AM 2 128 Feb 10, 2022 10:19 AM
Last Post: QU35T
[Python] by MomentumAug 24, 2021 03:54 PM 3 204 Aug 24, 2021 03:54 PM
Last Post: Momentum