How do you export data from Excel into Python using For Loops? -


i have figure out how print data excel spreadsheet using for loop, know export each column different variable can manipulate them, example plot graph using plot.ly

what have used far is;

import xlrd book = xlrd.open_workbook('filelocation/file.xlsx') sheet = book.sheet_by_index(0)  j in range(1,4):      in range(2,8785):          print "%d" %sheet.cell_value(i,j) 

which prints numbers spreadsheet terminal not useful.

but this;

import xlrd book = xlrd.open_workbook('filelocation/file.xlsx') sheet = book.sheet_by_index(0)  j= 1:      in range(2,8785):          time= "%s" %sheet.cell_value(i,j)  j= 2:     in range(2,8785):          sys= "%s" %sheet.cell_value(i,j)         

which declare different variables each column. understand error message seem using loops wrong, not familiar loops in python, have used them in matlab.

* edit * fixed indentation in question, fine in original code, not source of error.

i pandas sort of thing.

you can create dataframe object hold data you're looking for:

import pandas pd  df = pd.read_excel('myfile.xlsx', sheetname='sheet1') 

now can access each column name out of dataframe, if had column called 'mynumbers' (idk) py doing:

print df['mynumbers'] 

or iterate on columns using:

for col in df.columns:     print df[col] 

then can whatever like, including built-in plotting, visualisation , stats if have around docs.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -