File size: 586 Bytes
22e1e71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import csv
import random

# Step 1: Import the necessary modules

# Step 2: Open the CSV file in read mode
filename = "Apr.csv"  # Replace 'your_file.csv' with your actual file path
with open(filename, 'r', newline='') as csvfile:
    # Step 3: Read all rows into a list
    reader = csv.reader(csvfile)
    rows = [row for row in reader]

    # Step 4: Generate a random index
    random_index = random.randint(0, len(rows) - 1)

    # Step 5: Retrieve the row at the random index
    random_row = rows[random_index]

    # Step 6: Print or process the random row
    print(random_row)