How can find the position use specified value in sheet of excel?

99 views
Skip to first unread message

Yulong Zhao

unread,
May 18, 2014, 3:40:32 PM5/18/14
to python...@googlegroups.com
Hello everyone:

     I have no experience in python...@ @
  
     I want to know how can find the position use specified value in sheet of excel,and save the content of col to dictionary.for example:

name                    age             addr             phone
aaa                        2              xxxxxx            556
bbb                        4              xxxxx              555

I want to find the cell of age=4  position,and get all col values :name:bbb age:4 addr... phone... to save a dictionary

    should i read all content form sheet of excel,and write them to dictionary or loop sheet of cell to find it?

    Thanks  for answer..beforehand...


Adrian Klaver

unread,
May 19, 2014, 8:49:14 PM5/19/14
to python...@googlegroups.com
On 05/18/2014 12:40 PM, Yulong Zhao wrote:
> Hello everyone:
>
> I have no experience in python...@ @
> I want to know how can find the position use specified value in
> sheet of excel,and save the content of col to dictionary.for example:

Actually from below you want to save the row.

>
> name age addr phone
> aaa 2 xxxxxx 556
> bbb 4 xxxxx 555
>
> I want to find the cell of age=4 position,and get all col values
> :name:bbb age:4 addr... phone... to save a dictionary
>
> should i read all content form sheet of excel,and write them to
> dictionary or loop sheet of cell to find it?

Walk through the header row and create a dictionary that maps the
headers to column indices.
Iterate through the rows and then the cells in the row and find the cell
value you want.
You now have the row number and the row.
Walk through the columns in the row and use the header dictionary from
above to create a row dictionary that maps the column headers to the
column values.

>
> Thanks for answer..beforehand...
>



--
Adrian Klaver
adrian...@aklaver.com
Reply all
Reply to author
Forward
0 new messages