0

I have a csv file as shown below

Year, Growth
1, 10
2, 12
3, 13
4, 15

I would like to convert content of the csv file to an array say my_array, so that I can access growth as show below

my_array[1] should return 10

my_array[4] should return 15 etc

How can I convert the csv to such an array using pandas?

2
  • 1
    This is what is you are looking for (stackoverflow.com/questions/40238848/…) Commented Jul 31, 2019 at 5:56
  • But I need to access values as my_array[4]. Is it possible with that? Commented Jul 31, 2019 at 6:55

1 Answer 1

0
>>> import pandas
>>> df = pandas.read_csv('test.csv')
>>> df
   Year  Growth
0      1      10
1      2      12
2      3      13
3      4      15
>>> arr = df['Growth'].values.tolist()
>>> arr[0]
10

Yes , above piece of code will help you do that for whatever columns you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.