0

Hi I want to get values from first column of excel file as array.

Already I wrote this code-

import os
import pandas as pd

for file in os.listdir("./python_files"):
    if file.endswith(".xlsx"):
        df = pd.read_excel(os.path.join("./python_files", file))   
        print(df.iloc[:,1])

What i got in output now

0       172081
1       163314
2       173547
3       284221
4       283170
         ...
3582    163304
3583    160560
3584    166961
3585    161098
3586    162499
Name: Organization CRD#, Length: 3587, dtype: int64

What I whish to get

172081
163314
173547
284221
283170
  ...
163304
160560
166961
161098
162499

Can somebody help? Thanks :D

2 Answers 2

3

You will just need to use the tolist function from pandas:

import os
import pandas as pd

for file in os.listdir("./python_files"):
    if file.endswith(".xlsx"):
        df = pd.read_excel(os.path.join("./python_files", file)) 
        print(df.iloc[:,1].tolist())

Output

172081
163314
173547
284221
283170
  ...
163304
160560
166961
161098
162499
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I was looking for :D Thanks a lot
1

As an array:

df.iloc[:,1].values

As a list:

df.iloc[:,1].values.tolist()

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.