Python Forum
Open previous csv file to read value under column for comparison
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Open previous csv file to read value under column for comparison
#1
Hello,

I  need to check the value under the columns of two csv files (the current open file and the csv file written immediately before it) and if the value in the number column exists in the previous csv file, check to see if the value in the commits column is the same.  If they are different, do something (there are more columns in the csv than listed).  I'm having trouble trying to construct the correct comparison.  What I have now is minimal, not working and I'm stuck  Smile . Thanks for any help provided.

current.csv:
Number, Commits
1,              1,           
prevous.csv:
Number, Commits
1,             2

previous_csv = sorted(glob.iglob(reporting_path + '/' + '*.csv'), key=os.path.getctime)[-2]
with open(current_csv, 'r') as f:
      print(previous_csv)
Reply
#2
Hello!
Just keep the values in a variable and when read the second .csv compare them
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Thanks for the reply. That's the part I can't quite figure out is how to get the values under the header column into a variable for comparison.
Reply
#4
import csv

with open('data.csv', 'rb') as f:
    data = csv.reader(f, delimiter=',')
    for row in data:
        # each row of the csv file is a list of strings so you can get one and compare it with what you want
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help copying a column from a csv to another file with some extras g0nz0uk 3 456 Feb-01-2024, 03:12 PM
Last Post: DeaD_EyE
  Open/save file on Android frohr 0 315 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,087 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Recommended way to read/create PDF file? Winfried 3 2,869 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,429 Nov-09-2023, 10:56 AM
Last Post: mg24
  How can i combine these two functions so i only open the file once? cubangt 4 852 Aug-14-2023, 05:04 PM
Last Post: snippsat
  read file txt on my pc to telegram bot api Tupa 0 1,106 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,105 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,253 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,505 Jun-06-2023, 06:37 PM
Last Post: rajeshgk

Forum Jump:

User Panel Messages

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