Re: [Tutor] How would I replace the data of a Pandas Series with the values of a dictionary?

2019-07-18 Thread Albert-Jan Roskam


On 16 Jul 2019 23:31, Daniel Bosah  wrote:

Hi all,

I have a problem trying to match items in a dict and pandas series in
Python.

I have a dict ( called city_dict )of cities and city_id's ; for each city (
which is a key in the dict ), a unique city_id is a value in that dict.

So for example, city_dict = { New York : 1001, LA : 1002, Chicago : 1003 }.
New York is a key, 1001 is a value.

Now I have a panda Series called dfCities. In this series is a bunch of
cities, including the cities in city_dict.

My goal is to replace the cities in dfCities with the city_id's in a brand
new csv file. So if dfCities has New York in it, I want to replace it with
it's value in the dictionary, so 1001.


=》 check out 
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.replace.html.
 It accepts a dict, see also examples below.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] pass arg to list

2019-07-18 Thread Anirudh Tamsekar
Hi,


I'm trying to pass arguments to list.

This script needs to generate csv files. I want to pass the version and
build number to the script and it should be passed to the list.

My script below is blowing index out of range after adding the args.
However, if I hardcode the version, it works fine.
Kindly advise.



# User Args

version = sys.argv[1]

build = sys.argv[2]





add_file = (

['AddFile',

 109102010,

 'Product-'+version + 'Package (Build' + build + ')',

 'Product-'+version+'-b'+build+'-package.pkg',

 'Product-'+version + 'Service Package (Build' + build +  ')',

 version,

 ''],

)







Traceback (most recent call last):

  File "/Users/atamsekar/Projects/PulseSO/trunk/swrelease/samplexls.py",
line 5, in 

version = sys.argv[1]

IndexError: list index out of range



Process finished with exit code 1



-Thanks,

Anirudh Tamsekar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pass arg to list

2019-07-18 Thread Alan Gauld via Tutor
On 18/07/2019 19:34, Anirudh Tamsekar wrote:

> # User Args
> 
> version = sys.argv[1]
> build = sys.argv[2]
> 
> add_file = (...
> )

> Traceback (most recent call last):
> 
>   File "/Users/atamsekar/Projects/PulseSO/trunk/swrelease/samplexls.py",
> line 5, in 
> 
> version = sys.argv[1]
> 
> IndexError: list index out of range

The obvious thing to do is add a print statement before the asignments

print(sys.argv)

and check that it contains your expected values.


If that doesn't help show us your full code (including import
statements) and your full execution output, including whree you
call the program.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pass arg to list

2019-07-18 Thread Steven D'Aprano
On Thu, Jul 18, 2019 at 11:34:09AM -0700, Anirudh Tamsekar wrote:

> My script below is blowing index out of range after adding the args.

> version = sys.argv[1]

> Traceback (most recent call last):
>   File "/Users/atamsekar/Projects/PulseSO/trunk/swrelease/samplexls.py",
> line 5, in 
> version = sys.argv[1]
> IndexError: list index out of range


The obvious question is, are you passing command line arguments to your 
script?

How are you calling your script? If you are running it from an IDE you 
need to tell the IDE to include command line arguments.

If you run it like this, from the operating system's command line:

python samplexls.py

then there are no command line arguments and sys.argv[1] will be out of 
range. You need to run something like this:

python samplexls.py argument1 argument2


Try putting:

print(sys.argv)

at the start of your script and see what is there.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Web framework module for Python.

2019-07-18 Thread Ben Finney
 writes:

> The web page is not going to have any fancy structure or visual effects at
> all. I am more than happy to hand-code the HTML/JavaScript. I have had a
> quick search and found a range of modules. Most of them indicate they are
> for CMS web sites and look far to complex for my needs. 
>
> If someone could point myself to a module and possibly a tutorial for the
> module. I would be grateful. Hopefully this is not to of a open question.

It's a good question. You have an answer that directs you to the Python
tutorial.

If you want to go beyond that, the Python Wiki has many suggestions
https://wiki.python.org/moin/WebProgramming> and for frameworks
specifically https://wiki.python.org/moin/WebFrameworks> (some may
be out of date though). Each has a short description, you can use that
to gauge whether you want to explore.

-- 
 \   “The Initial Mystery that attends any journey is: how did the |
  `\   traveller reach his starting point in the first place?” —Louise |
_o__)  Bogan, _Journey Around My Room_ |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Lengthy copyright notices?

2019-07-18 Thread Ben Finney
David L Neil  writes:

> There can be quite an accumulation of 'paper-work' at the top of
> modules, which then has to be scrolled-through before we can get
> stuck-in to function/class/__main__ code - even with an editor's
> code-folding assistance.
>
> Should it be left to the (far) end of the file? Would it lessen any
> legal implication?

I am more commonly using:

* Top of file has a brief (3-line) declaration, in a comment, that this
  is free software, you are free to modify and redistribute under
  certain conditions; see the end of the file.

* End of file has full copyright information: copyright statements
  (years and holders), standard boilerplate grant of freedoms,
  disclaimer of warranty, and specific filename where the full legal
  license document is to be found.

> Aside from possibly irritating 'the good guys', does such really
> 'stop' a determined rapscallion?

The good guys also need to have a clear idea of exactly who claims what,
and exactly what freedoms they have in exactly what work when they
receive it.

Files have a tendency to migrate from work to work, and so it's not
uncommon to have multiple works combined with different declarations
that apply. It's good to attach this information directly in the file.

I see no good reason why it needs to be all at the top of the file,
though. To my eye, a very brief “you're free to do this set of things,
see the end of this file for details” is notifying the reader without
over-burdening them every time they open the file.

-- 
 \   “Theology is the effort to explain the unknowable in terms of |
  `\ the not worth knowing.” —Henry L. Mencken |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor