Home > OS >  Copy column from excel to array in python
Copy column from excel to array in python

Time:11-20

I have values in an excel sheet that I want to easily transfer to my Python code. Is there any easy way to select all the cells you want from the sheet and then copy-paste them into the text editor with each cell value separated with a comma?

CodePudding user response:

You may use pandas to do it:

import pandas as pd
df = pd.read_excel('your_file.xslx', sheetname='your_sheet_name')
your_array = df['your_column_name'].toarray()

CodePudding user response:

If you are not doing the process too often you can copy to a text editor e.g. notepad and then do a find and replace for new line ('\r\n') to ',' with extended search mode.

enter image description here

CodePudding user response:

If you copy-paste a column, the values will be seperated by a line break. You can seperate it, by the Python REPL, if you assign it to a string variable (using triple quote), then use a = yourstring.split() to seperate the values to an array, and then a.join(',') to split by a comma, as a string parsed values.

  • Related