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
  open a text file using list() Pedroski55 2 116 Feb-25-2026, 06:57 PM
Last Post: noisefloor
  If I open a file write or append, is the file loaded into RAM? Pedroski55 11 1,118 Jan-14-2026, 07:49 AM
Last Post: Pedroski55
Question [SOLVED] Open file, and insert space in string? Winfried 7 2,524 May-28-2025, 07:56 AM
Last Post: Winfried
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 2,972 Dec-19-2024, 11:57 AM
Last Post: snippsat
  Trying to open depracated joblib file mckennamason 0 2,156 Sep-19-2024, 03:30 PM
Last Post: mckennamason
  Read TXT file in Pandas and save to Parquet zinho 2 2,536 Sep-15-2024, 06:14 PM
Last Post: zinho
  Pycharm can't read file Genericgamemaker 5 3,091 Jul-24-2024, 08:10 PM
Last Post: deanhystad
  Python is unable to read file Genericgamemaker 13 8,177 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 4,841 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Help copying a column from a csv to another file with some extras g0nz0uk 3 2,864 Feb-01-2024, 03:12 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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