Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6045039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:04:50+00:00 2026-05-23T07:04:50+00:00

This is my first time working with python. I’m trying to create a dictionary

  • 0

This is my first time working with python. I’m trying to create a dictionary for each county (23 in total) with year as the key for population and income values. Strong arming the code seems to work, but I’m sure there is an easier way to do it using loops or classes…any suggestions?? Thanks!!!!!

import xlrd

wb= xlrd.open_workbook('C:\Python27\Forecast_test.xls')

popdata=wb.sheet_by_name(u'Sheet1')
incomedata=wb.sheet_by_name(u'Sheet2')

WyomingCnty =('Albany', 'Big Horn',
        'Campbell', 'Carbon', 'Converse',
        'Crook', 'Fremont', 'Goshen',
        'Hot Springs','Johnson', 'Laramie',
        'Lincoln', 'Natrona','Niobrara',
        'Park', 'Platte', 'Sheridan', 'Sublette',
        'Sweetwater', 'Teton', 'Uinta', 'Washakie', 'Weston','Wyoming')

Years = ('y0','y1','y2','y3','y4','y5','y6','y7','y8','y9','y10',
    'y11','y12', 'y13', 'y14', 'y15', 'y16', 'y17', 'y18','y19',
    'y20','y21','y22','y23','y24','y25','y26','y27','y28','y29','y30')

AlbanyPop = popdata.col_values(colx=1,start_rowx=1,end_rowx=None)
AlbanyIncome= incomedata.col_values(colx=1,start_rowx=1,end_rowx=None)
AlbanyDict1=dict(zip(Years,AlbanyPop))
AlbanyDict2=dict(zip(Years,AlbanyIncome))

BigHornPop = popdata.col_values(colx=2,start_rowx=1,end_rowx=None)
BigHornIncome= incomedata.col_values(colx=2,start_rowx=1,end_rowx=None)
BigHornDict1=dict(zip(Years,BigHornPop))
BigHornDict2=dict(zip(Years,BigHornIncome))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:04:51+00:00Added an answer on May 23, 2026 at 7:04 am
    popdict = {}
    incdict = {}
    for ix, city in enumerate(WyomingCnty):
      popdict[city] = dict(zip(Years, popdata.col_values(colx=ix + 1,start_rowx=1,end_rowx=None)
      incdict[city] = dict(zip(Years, incomedata.col_values(colx=ix + 1,start_rowx=1,end_rowx=None)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time working with Objective-C, and I keep trying to create
I'm pretty new to python. This is my first time working with classes in
I am new to Python and this is my first time asking a stackOverflow
I'm working with XML and Python for the first time. The ultimate goal is
This is the first time i am working with Lists and I don't seem
I'm working with QGraphicsView/Scene for the first time. This is in PyQt, but except
This is my first time working on a secure website. It's for a pet
This is my first time working on php code. I've put some printf code
I'm trying ajax for the first time but it doesn't work. This is some.php
For the first time, I was trying out one of my Python scripts, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.