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
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 1,128 Dec-19-2024, 11:57 AM
Last Post: snippsat
  Trying to open depracated joblib file mckennamason 0 737 Sep-19-2024, 03:30 PM
Last Post: mckennamason
  Read TXT file in Pandas and save to Parquet zinho 2 1,266 Sep-15-2024, 06:14 PM
Last Post: zinho
  Pycharm can't read file Genericgamemaker 5 1,597 Jul-24-2024, 08:10 PM
Last Post: deanhystad
  Python is unable to read file Genericgamemaker 13 3,782 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 3,327 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Help copying a column from a csv to another file with some extras g0nz0uk 3 1,749 Feb-01-2024, 03:12 PM
Last Post: DeaD_EyE
  Open/save file on Android frohr 0 1,129 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 7,413 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Recommended way to read/create PDF file? Winfried 3 4,804 Nov-26-2023, 07:51 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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