Python Pandas CSV

1

I started learning Python a short time ago and I'm doing a project to normalize client data. But I do not know how to make a comparison of type: reads the CSV field the CP7, searches for all CP7 of the CSV CTT and writes in the table PNorm , if you find only one address you type in CSV Norm , if you find more than 1 it continues to parse in the other fields.

import csv
import pandas as pd
import numpy as np

cp7 = []

cp4 = []

local = []

tv = []

nr = []

mor = []

nll = sum(1 for line in open('example.csv'))  # count the number of lines
nl = nll - 1

df1 = pd.read_csv("example.csv", names=['CP7', 'CP4', 'Local', 'TV', 'NR'])
df2 = pd.read_csv("CTT.csv", names=['CP7', 'CP4', 'Local', 'TV', 'NR'])
pn = pd.read_csv("PNorm.csv", names=['CP7', 'CP4', 'Local', 'TV', 'NR'])

for row in range(nl):
    if cp7 is True:

    # compare column with another csv file

        if cp7 == 1:  # cp7 matches with only one address
            File = open('Norm.csv', 'w')
            Norm = csv.writer(File)
            Norm = [row for col in Norm]
            File.close()
        else:  # all cp7 possibilities
            File = open('PNorm.csv', 'w')
            PNorm = csv.writer(File)
            PNorm = [row for col in PNorm]
            File.close()

    elif cp4 is True:  # all cp4 possibilities

    # compare column with another csv file

        File = open('PNorm.csv', 'w')
        PNorm = csv.writer(File)
        PNorm = [row for col in PNorm]
        File.close()
    else:
        pass

    if local is True:  # all local possibilities

    # read local

        File = open('PNorm.csv', 'w')
        PNorm = csv.writer(File)
        PNorm = [row for col in PNorm]
        File.close()
    else:
        pass

    if tv is True: # tipo de via

    # compare column with another csv file

        if tv == 1:  # TipVia matches with only one address
            File = open('Norm.csv', 'w')
            Norm = csv.writer(File)
            Norm = [row for col in Norm]
            File.close()
        else:  # all TipVia possibilities
            File = open('PNorm.csv', 'w')
            PNorm = csv.writer(File)
            PNorm = [row for col in PNorm]
            File.close()
    else:
        pass

    if nr is True:  # nome de rua e numero policia

    # compare column with another csv file

        if nr == 1:  # NomeRua_NumPol matches with only one address
            File = open('Norm.csv', 'w')
            Norm = csv.writer(File)
            Norm = [row for col in Norm]
            File.close()
        else:  # all possibilities
            File = open('PNorm.csv', 'w')
            PNorm = csv.writer(File)
            PNorm = [row for col in PNorm]
            File.close()
    else:
        pass
    
asked by anonymous 02.06.2017 / 16:25

0 answers