I have a python script which takes input from a admin.csv file. I want to read the latest entry in the admin.csv file, which is on the last line. Kindly help me out. My csv file is below.

Input_IP    Skip_Frames Save_Video  Id_Display
192.168.1.97    100             True    False
191.168.43.97   91              False   True
191.168.43.97   1               True    True
191.168.4.61    11              False   False
191.135.4.12    99              True    True

2 Answers

0
Miklos Horvath On Best Solutions

The csv reader is a generator, you can convert that to a list. You can get the last data in the last line with the following code sample:

import csv

with open('test.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=' ')
    print(list(csv_reader)[-1][-1])
0
Chinni On

One simple way if you are using pandas is

import pandas as pd

df = pd.read_csv('filename.csv')
df.iloc[-1]