Script to get list of ASN from a list of AS Organizations from .csv file

I came up with this it is not tested I don’t do python

import csv

# Initialize a list to store the ASNs
asns = []

# Open the CSV file
with open('your_file.csv', 'r') as csvfile:
    # Create a CSV reader
    csvreader = csv.reader(csvfile)
    # Skip the header row
    # Iterate through the rows in the CSV file
    for row in csvreader:
        # Extract the ASN from the 'asn' column (assuming it's in the 3rd column, index 2)
        asn = row[2]
        # Append the ASN to the list

# Define the path to the text file where you want to save the ASNs
output_file = 'asns.txt'

# Write the ASNs to the text file
with open(output_file, 'w') as txtfile:
    for asn in asns:
        txtfile.write(asn + '\n')

print(f"ASNs have been saved to {output_file}")

1 Like

@Abdullah Help Please

Hi there, nice to talk to you again.

Please kindly look into the documentation of Pandas because we were using it before to solve the initial question.

If you can invest a bit of time into understanding Python and Pandas, you can simply achieve your target solution.