0

I have a csv file containing two columns. I want to create 2 seperate arrays for each of the column in python. How do I proceed with doing that? Any suggestions would greatly help. i have attached a snippet of how my csv file looks like.

enter image description here

2
  • Can you please edit your post and put there sample of your CSV file (with correct formatting)? Commented Jul 4, 2021 at 18:57
  • Welcome to Stack Overflow. I recommend seeing one of these threads and looking at how the search functionality works. Commented Jul 4, 2021 at 21:03

1 Answer 1

0

To load the CSV file into two lists:

import csv

col1 = []
col2 = []
with open("your_file.csv", "r") as f_in:
    reader = csv.reader(f_in)
    next(reader)  # skip headers

    for line in reader:
        col1.append(float(line[0]))
        col2.append(float(line[1]))

print(col1)
print(col2)

Prints:

[-7.66e-06, -7.6e-06, -7.53e-06]
[17763.0, 2853.0, 3694.0]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.