Re: [Tutor] What is Tuple in the typing module?

2019-08-20 Thread C W
Thank you, Peter and Alan. Both very helpful. I was able to figure it out.
Cheers!

On Sat, Aug 17, 2019 at 5:45 AM Alan Gauld via Tutor 
wrote:

> On 17/08/2019 00:46, C W wrote:
>
> The formatting seems messed up I'll try to straighten it out.
> I hope I get it right!
>
> Caveat: I'm no expert in the typing module, I've read the
> docs but never found any use for it.
>
> > What exactly is Tuple in the typing module? What does it do?
>
> It specifies a tuple type. I assume you understand what
> a tuple is in regular Python code?
>
> > This is the definition from its website.
> > https://docs.python.org/3/library/typing.html
> > "A type alias is defined by assigning the type to the alias"
> >
> > I have no idea what that means.
>
> It just means that an alias is a label that you can use
> to signify a type. And you can effectively create new
> "types" by combining simpler types
>
>
> > Here's the example from the documentation:
> >
> > from typing import Dict, Tuple, Sequence
> ConnectionOptions = Dict[str, str]
> Address = Tuple[str,int]Server  = Tuple[Address, ConnectionOptions]
>
> So this creates 3 new type aliases: ConnectionOptions, Address, Server
> which are defined in terms of basic Python types,.
> So Address is a tuple of a string and integer.
>
> > def broadcast_message(message: str, servers: Sequence[Server]) -> None:
>
> Ad this defines a function where the parameter types are
> specified in terms of the new type names that we just
> created.
>
> > # The static type checker will treat the previous type signature as#
> > being exactly equivalent to this one.
>
> > def broadcast_message(
> > message: str,
> > servers: Sequence[Tuple[Tuple[str, int], Dict[str, str]]]) ->
> None:
>
> And this is the same function but with the parameters expanded
> into their traditional basic types.
>
> Without all the type hinting gubbins it would simply be:
>
> def broadcast_message(message, servers):
>  
>
> So all the detritus above is doing is attempting to make it
> clearer what the two parameters actually are in data terms.
> The first is a string, the second is a complex structure
> of nested tuples and a dict (which probably should all
> be wrapped in a class!).
>
> > I think this even more confusing. Can someone explain this in simple
> words?
> > I don't have a intense computer science background.
>
> Type hints are a way to specify the types of function parameters.
> They are an attempt to make complex type structures more readable
> rather than fixing the data to be simpler (which, to be fair,
> may not always be possible/easy). They are also an attempt to
> bring some of the "benefits" of static typing into Python but
> with very limited success. But they are only hints, you can
> happily survive without them.
>
> --
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] What is Tuple in the typing module?

2019-08-17 Thread C W
Hi everyone,

What exactly is Tuple in the typing module? What does it do?

This is the definition from its website.
https://docs.python.org/3/library/typing.html
"A type alias is defined by assigning the type to the alias"

I have no idea what that means.

Here's the example from the documentation:

from typing import Dict, Tuple, Sequence
ConnectionOptions = Dict[str, str]Address = Tuple[str, int]Server =
Tuple[Address, ConnectionOptions]
def broadcast_message(message: str, servers: Sequence[Server]) -> None:
...
# The static type checker will treat the previous type signature as#
being exactly equivalent to this one.def broadcast_message(
message: str,
servers: Sequence[Tuple[Tuple[str, int], Dict[str, str]]]) -> None:
...


I think this even more confusing. Can someone explain this in simple words?
I don't have a intense computer science background.

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


Re: [Tutor] How to convert string to date time format?

2019-07-23 Thread C W
Thanks a lot Steven. The %f is what I was missing.

The "-08:00" is the UTC timezone, which is California, USA, which I believe
is %z.

Thanks!

On Sat, Jul 20, 2019 at 7:50 PM Steven D'Aprano  wrote:

> On Fri, Jul 19, 2019 at 10:44:36PM -0400, C W wrote:
> > Hello all,
> >
> > I have a date time string that looks like the following.
> >
> > 02015-07-01 00:01:44.538420-08:00
> > 12015-07-01 00:27:58.717530-08:00
> > 22017-07-01 07:07:48.391376-08:00
>
> I assume that the leading number and spaces "0" etc are NOT part of
> the strings.
>
>
> > I have tried the following two different methods, both did not work.
> > Method one: pandas
> > import pandas as pd
> > stamp = pd.to_datetime(my_string, format='%Y%m%d %H:%M:%S')
> >
> > Method two: datetime package
> > from datetime import datetime
> > datetime.strptime(my_string, '%Y-%m-%d %H:%M:%S')
> >
> >
> > Are both ways suppose to work?
>
> Not unless the string format matches the actual string. You can't expect
> to convert a string unless it matches the format.
>
>
> > Also, does it matter if there are decimals
> > after seconds?
>
> Of course it matters.
>
> Did you read the error message? The single most important skill for a
> programmer is to READ THE ERROR MESSAGE and pay attention to what it
> tells you went wrong:
>
> py> datetime.strptime('2015-07-01 00:01:44.538420-08:00', '%Y-%m-%d
> %H:%M:%S')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/local/lib/python3.5/_strptime.py", line 510, in
> _strptime_datetime
> tt, fraction = _strptime(data_string, format)
>   File "/usr/local/lib/python3.5/_strptime.py", line 346, in _strptime
> data_string[found.end():])
> ValueError: unconverted data remains: .538420-08:00
>
>
> See how the error message tells you that it couldn't convert the string
> because there is data left over at the end. The first thing to do is
> handle the microseconds.
>
> Googling gets the answer: use "%f" as the code for fractional seconds.
>
> https://duckduckgo.com/?q=strptime+seconds+with+decimals
>
>
> py> datetime.strptime('2015-07-01 00:01:44.538420-08:00', '%Y-%m-%d
> %H:%M:%S.%f')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/local/lib/python3.5/_strptime.py", line 510, in
> _strptime_datetime
> tt, fraction = _strptime(data_string, format)
>   File "/usr/local/lib/python3.5/_strptime.py", line 346, in _strptime
> data_string[found.end():])
> ValueError: unconverted data remains: -08:00
>
>
> Now we're making progress! The error message has changed. Now you just
> need to decide what the "-08:00" part means, and change the format
> string appropriately.
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to convert string to date time format?

2019-07-20 Thread C W
Hello all,

I have a date time string that looks like the following.

02015-07-01 00:01:44.538420-08:00
12015-07-01 00:27:58.717530-08:00
22017-07-01 07:07:48.391376-08:00

I have tried the following two different methods, both did not work.
Method one: pandas
import pandas as pd
stamp = pd.to_datetime(my_string, format='%Y%m%d %H:%M:%S')

Method two: datetime package
from datetime import datetime
datetime.strptime(my_string, '%Y-%m-%d %H:%M:%S')


Are both ways suppose to work? Also, does it matter if there are decimals
after seconds? Thanks a lot!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's the difference between calling a method with parenthesis vs. without it?

2018-06-19 Thread C W
Thank you all. I'm relatively new to OOP, I think that's where the problem
is. It's different from C or any C alike language.

I'm still figuring out what's under the hood with OOP.

Thanks!

On Mon, Jun 18, 2018 at 8:26 PM, Steven D'Aprano 
wrote:

> On Mon, Jun 18, 2018 at 08:50:24AM -0600, Mats Wichmann wrote:
>
> > Python is not like certain other languages.
>
> But it is like *other* certain other languages.
>
> :-)
>
> Python's execution model is different from C, Pascal or Fortran, but it
> is quite similar to Ruby, Lua and Javascript.
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] What's the difference between calling a method with parenthesis vs. without it?

2018-06-18 Thread C W
Dear Python experts,

I never figured out when to call a method with parenthesis, when is it not?
It seems inconsistent.

For example,
If I do

> data.isnull()

numberair_pressure_9amair_temp_9amavg_wind_direction_9amavg_wind_speed_9am
max_wind_direction_9ammax_wind_speed_9amrain_accumulation_9am
rain_duration_9amrelative_humidity_9amrelative_humidity_3pm
0 False False False False False False False False False False False
1 False False False False False False False False False False False
2 False False False False False False False False False False False

Or I can do without parenthesis,
> data.isnull

 data.columns

Index(['number', 'air_pressure_9am', 'air_temp_9am', 'avg_wind_direction_9am',
   'avg_wind_speed_9am', 'max_wind_direction_9am', 'max_wind_speed_9am',
   'rain_accumulation_9am', 'rain_duration_9am', 'relative_humidity_9am',
   'relative_humidity_3pm'],
  dtype='object')


# with parenthesis throws an error
> data.columns()

---TypeError
Traceback (most recent call
last) in ()> 1
data.columns()
TypeError: 'Index' object is not callable


I always thought columns(), isnull() are methods to objects, so, you would
need to pass parameters even when it's empty. But, apparently I am wrong on
this.

What is going on?

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


Re: [Tutor] In matplotlib, why are there axes classes vs. axes API? Why not list them under one documentation?

2018-06-17 Thread C W
I have found the matplotlib list.

Cheers!

On Sat, Jun 16, 2018 at 7:13 PM, Alan Gauld via Tutor 
wrote:

> On 16/06/18 05:49, Mike C wrote:
> > I can only compare to the R language I've used. If there is an issue,
> > say a function freezes at startup, one user brings it up to the list,>
> when the respective maintainer sees the bug, it is usually addressed
>
> Which is fine if there is a team working onthe project full time
>  - as there would be on a commercial project - perhaps by sponsorship.
> But many(most?) open source projects are not sponsored., they are
> a small (often just one or two) individuals working in their spare
> time.
>
> > In terms of funding. Isn't Python heavily used in industry,
>
> Yes and several companies sponsor development of the core
> python language. As such major issues tend to be addressed rapidly.
> But... matplotlib is not part of that core language.
>
> It is a part of ScyPy which is not used by such large
> numbers of industrial companies (and is more directly
> of interest to researchers and academics rather than
> commercial developers - a group best known for lack of
> funds!) and as such is less likely to be responsive,
> especially when the issues are not bugs or functionality
> affecting - they are just usability irritations.
>
>
> --
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] In matplotlib, why are there axes classes vs. axes API? Why not list them under one documentation?

2018-06-17 Thread C W
Somehow I missed your first post, Mats. I certainly agree with you earlier
point.

After searching, I see there is a Matplotlib list. I will direct questions
to there, hopefully that will bring some attention.

Thanks!

On Sat, Jun 16, 2018 at 11:52 AM, Mats Wichmann  wrote:

> On 06/15/2018 10:49 PM, Mike C wrote:
> > I can only compare to the R language I've used. If there is an issue,
> say a function freezes at startup, one user brings it up to the list, when
> the respective maintainer sees the bug, it is usually addressed on the next
> release.
>
>
> Sure.  So that suggests you ought to bring this up to the matplotlib
> community, and see if they are similarly responsive. We here are not
> connected to it, we only seek to give general advice to extent we are
> able to.
>
>
> > In terms of funding. Isn't Python heavily used in industry, so,
> financial contribution should've been huge, no?
>
>
> There's not really a connection... matplotlib is written in Python, yes,
> but as a discrete project is only going to attract interest from those
> who have a use for it, not from the broader "everybody who uses Python
> for something" community.  As would be the case for any independent open
> source project, irrespective of what programming language it is written
> in.  And that is indeed one of the differences between open source and
> commercial development... if there's not a company behind it, the nature
> of responses is likely to be different.  Which is not to say commercial
> companies prioritize things the way you'd want either.  I have recently
> proposed to one company that shall remain unnamed because this is only
> an example, not any attempt to cast blame, an improvement they could
> make to their project through a system they provide to propose features,
> and to vote on features others have proposed.  That feature now has 20
> votes and I was excited a lot of people agreed with me.  I just heard
> through independent channels that that company's developers don't even
> look at suggestions until the votes number in the thousands. Guess it's
> not happening...
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] In matplotlib, why are there axes classes vs. axes API? Why not list them under one documentation?

2018-06-15 Thread C W
I read through some documentations yesterday after posting.

I will share what I think. There are three parts to matplotlib: backend,
artist, and scripting. The artist layer is the only one that really matters
for matplotlib users.

Why haven't the developers fixed the problem? Considering Python's growing
popularity, hasn't anyone brought this up before me? Was there a plan?

Thanks!





On Thu, Jun 14, 2018 at 9:39 PM, Steven D'Aprano 
wrote:

> On Thu, Jun 14, 2018 at 12:31:44PM -0400, C W wrote:
> > Hello everyone,
> >
> > I'm working on matplotlib, could someone explain the difference between
> > these two?
> >
> > Axes class: https://matplotlib.org/api/axes_api.html#matplotlib.axes.
> Axes
> > Axes and tick API: https://matplotlib.org/api/axis_api.html
> >
> > I began at reading axes class, but discovered axes API by accident. Why
> are
> > there two documentations on the same thing? Why not merge? I mean, one is
> > already confusing enough. ;)
>
> *shrug*
>
> Because the designers of matplotlib suck at designing a good, easy to
> use, easy to understand, simple API? Because they're not good at writing
> documentation? I dunno.
>
> It is hard to write an API which is both *obvious* and *powerful*, but
> the few times I tried using matplotlib I found it baroque and confusing.
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] In matplotlib, why are there axes classes vs. axes API? Why not list them under one documentation?

2018-06-14 Thread C W
Hello everyone,

I'm working on matplotlib, could someone explain the difference between
these two?

Axes class: https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes
Axes and tick API: https://matplotlib.org/api/axis_api.html

I began at reading axes class, but discovered axes API by accident. Why are
there two documentations on the same thing? Why not merge? I mean, one is
already confusing enough. ;)

Axes is already branching off of plt,plot(), and now there is a branch
within axes. I didn't dare to look, but may even be sub-branches?

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


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-27 Thread C W
Today, I ran into ellipsis again. This time, it is COMPLETELY different
from before.

Here is a reproducible code:

import numpy as np
import matplotlib.pyplot as plt
...
x = np.linspace(0, 1)
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
plt.title('Week cycle')
plt.xlabel('Month')
plt.ylabel('Price')
plt.plot(x, y)


If I leave out the ellipsis, plot title and label will not show. It's doing
interactive plot. How am I suppose to know ellipsis is doing interactive
plotting? No way I could have guessed.

Matplotlib documentation <https://matplotlib.org/> explains that it
recreated itself from Matlab plots.

Is it something similar to Matlab like
>>> hold on;

That's fine! But, how many identities will ellipsis take on? How do you
experienced users deal with these ambiguities?



On Fri, Aug 11, 2017 at 9:24 PM, Steven D'Aprano <st...@pearwood.info>
wrote:

> On Fri, Aug 11, 2017 at 07:57:09AM -0600, Mats Wichmann wrote:
> > On 08/10/2017 05:23 PM, Alan Gauld via Tutor wrote:
> > > On 10/08/17 14:39, C W wrote:
> > >
> > >> I suppose it's just a place holder, though I don't know when I would
> use it
> > >> in my every day life.
> > >
> > > Probably never.
> > >
> > > Like most programming languages Python has a load of rarely used,
> > > obscure features. Most Python programmers never use ellipses,
> >
> > I guess what this means is when I post code snippets with some lines
> > elided for greater readability of the point being made I should not use
> > ellipses for that, as they're actually a syntactic element!   :)
>
> No, go right ahead and continue using ... for elided lines. Python 3
> makes that syntactically legal, and the fact that elided code may be
> syntactically correct is one of the reasons that was done.
>
> In Python 2, ... was just the *display* form of Ellipsis, and wasn't
> legal except in slice notation: a[...]. Python 3 made ... syntactic
> sugar for Ellipse everywhere, not just in slices, which makes:
>
> x = ...
>
> class X:
> ...
>
> perfectly legal code. (Perhaps not *meaningful* code, but that's okay.)
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does matplotlib.finance still work?

2017-08-26 Thread C W
Thanks Alan. You are right, the finance.py is there.

I think quotes_historical_yahoo is from 3 years ago. It is replaced by
quotes_historical_yahoo_ochl and quotes_historical_yahoo_ohlc.

But the problem is, yahoo finance has also changed its API (2 years ago?).
It is a complete overhaul.

quotes_historical_yahoo_ochl has not kept up. Thus, the error message.

help(quotes_historical_yahoo_ochl)
--
Help on function quotes_historical_yahoo_ochl in module matplotlib.finance:
quotes_historical_yahoo_ochl(ticker, date1, date2, asobject=False,
adjusted=True, cachename=None) Get historical data for ticker between date1
and date2. See :func:`parse_yahoo_historical` for explanation of output
formats and the *asobject* and *adjusted* kwargs. Parameters --
ticker : str stock ticker date1 : sequence of form (year, month, day),
`datetime`, or `date` start date date2 : sequence of form (year, month,
day), `datetime`, or `date` end date cachename : str or `None` is the name
of the local file cache. If None, will default to the md5 hash or the url
(which incorporates the ticker and date range) Examples  >>> sp =
f.quotes_historical_yahoo_ochl('^GSPC', d1, d2, asobject=True,
adjusted=True) >>> returns = (sp.open[1:] - sp.open[:-1])/sp.open[1:] >>>
[n,bins,patches] = hist(returns, 100) >>> mu = mean(returns) >>> sigma =
std(returns) >>> x = normpdf(bins, mu, sigma) >>> plot(bins, x,
color='red', lw=2)

Thank you very much!

On Fri, Aug 25, 2017 at 1:01 PM, Alan Gauld via Tutor <tutor@python.org>
wrote:

> On 25/08/17 15:19, C W wrote:
> > I did not mean to leave out the error message, it was very long.
>
> That just means it has a lot of information in it :-)
>
> >  I think the package has been removed.
>
> I don;t think so based on the traceback...
>
> >>>> quotes = quotes_historical_yahoo_ochl('APX', start, ... )
> > --
> > TypeError: quotes_historical_yahoo_ochl() missing 1 required positional
> > argument: 'date2'
>
> Did you check what parameters were required for this function?
> The error says you are missing one.
>
> > /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in
>
> Note the filename. That suggests finance.py is still there.
>
> > quotes_historical_yahoo_ochl(ticker, date1, date2, asobject, adjusted,
> > cachename) 411 return _quotes_historical_yahoo(ticker, date1, date2,
> > asobject=asobject, 412 adjusted=adjusted, cachename=cachename, --> 413
> > ochl=True) 414 415
> > /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in
> > _quotes_historical_yahoo(ticker, date1, date2, asobject, adjusted,
> > cachename, ochl) 501 # warnings.warn("Recommend changing to
> asobject=None")
> > 502 --> 503 fh = fetch_historical_yahoo(ticker, date1, date2, cachename)
> 504
> > 505 try:
>
> Some warnings there that might be relevant, I don't know
> anything about the package or function.
>
> You could try running the help() function:
>
> >>> help(quotes_historical_yahoo_ochl)
>
> And see if it shows anything useful.
>
> --
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does matplotlib.finance still work?

2017-08-25 Thread C W
3.6/urllib/request.py in http_open(self, req) 1344
1345 def http_open(self, req): -> 1346 return self.do_open(http.client.
HTTPConnection, req) 1347 1348 http_request = AbstractHTTPHandler.
do_request_
/Users/anaconda/lib/python3.6/urllib/request.py in do_open(self,
http_class, req, **http_conn_args) 1318
encode_chunked=req.has_header('Transfer-encoding')) 1319 except OSError as
err: # timeout error -> 1320 raise URLError(err) 1321 r = h.getresponse()
1322 except:
URLError: 

On Fri, Aug 25, 2017 at 6:01 AM, Sydney Shall <s.sh...@virginmedia.com>
wrote:

> On 24/08/2017 18:46, Alan Gauld via Tutor wrote:
>
>> On 24/08/17 14:51, C W wrote:
>>
>> I have the following code, I get an error at the first line.
>>>
>>
>> So don't make us guess. What is the error(full text please)?
>>
>> from matplotlib.finance import quotes_historical_yahoo_ochl
>>>
>>
>> And what does a dir() show for matplotlib.finance?
>> Are you sure the name is spelled right etc?
>>
>> I have heard this package is either upgraded or replaced. If so, what do
>>> you recommend?
>>>
>>
>> Contact its author perhaps?
>>
>>
>
> Is this the answer, perhaps.
>
> >>>import matplotlib
>
> >>>dir(matplotlib.finance)
> >>>Traceback (most recent call last):
>
>   File "", line 1, in 
> dir(matplotlib.finance)
>
>   AttributeError: module 'matplotlib' has no attribute 'finance'
>
> Thanks to Alan G? for his excellent teaching.
>
> --
> Sydney
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Does matplotlib.finance still work?

2017-08-24 Thread C W
Hello all,

I have the following code, I get an error at the first line.

from matplotlib.finance import quotes_historical_yahoo_ochl
from datetime import date
import pandas as pd
today = date.today()
start = date(today.year-1, today.month, today.day)
quotes = quotes_historical_yahoo_ochl('APX', start, today)


I have heard this package is either upgraded or replaced. If so, what do
you recommend?

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


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-10 Thread C W
What's a literal? The only other time I heard about it was studying
Shakespare. ;)

I don't know what literal is. So, it won't help me to understand ellipsis,
I really thought it was that oval shaped figure.

Wiki says: "Literals are often used to initialize variables"

https://en.wikipedia.org/wiki/Literal_(computer_programming)

I suppose it's just a place holder, though I don't know when I would use it
in my every day life.

On Thu, Aug 10, 2017 at 8:47 AM, Steven D'Aprano <st...@pearwood.info>
wrote:

> On Wed, Aug 09, 2017 at 12:06:37PM -0400, C W wrote:
> > Dear Python experts,
> >
> > What exactly does the three dots do?
> > > aList = ...
>
> ... is literal syntax for the Ellipsis singleton object.
>
> Ellipsis was added to the language at the express request of the numpy
> developers. Although numpy is a third-party project outside of the
> standard library, it is big enough and important enough that their
> requests carry a LOT of weight with the core Python devs. Other features
> Python has that were originally added at the request of numpy include:
>
> - extended slicing with two colons obj[a:b:c]
>
> - the @ operator used by numpy for matrix multiplication.
>
> I don't know what Ellipsis is used for by numpy, but now it makes a
> convenient pseudo-pass command:
>
> class X:
> ...
>
> def func():
> ...
>
>
> > It's an ellipsis, a spot holder to later. But what data type is it:
> vector,
> > matrix?
>
> Its a singleton object. Think of it as a sibling to None and
> NotImplemented, but with optional funny syntactic sugar ... to refer to
> it.
>
> None is a special value used as "no such value", or nil or null;
>
> NotImplemented is a special value used by operator dunder methods like
> __add__ and __mul__ to mean "I can't handle this argument";
>
> Ellipsis is a special value used by numpy to mean whatever it is that
> numpy uses it to me.
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] If tuple cannot be sorted, then why sorted() on a tuple is fine?

2017-08-09 Thread C W
This is a follow up. I actually ran into this today:

import numpy as np
xArray = np.ones((3, 4))

> xArray.shape
(3, 4)
> np.shape(xArray)
(3, 4)

It was confusing to see that both xArray.shape and np.shape() worked. Are
they equivalent?

In the case of sort() vs sorted(), they are different, but close enough to
mistake them as the same thing.

Thanks!

On Wed, Aug 2, 2017 at 9:32 PM, C W <tmrs...@gmail.com> wrote:

> As pointed out by someone else, ?sorted
> sorted(iterable, key=None, reverse=False)
>
> It seems like the only requirement is iterable. I guess tuple is iterable,
> so, it doesn't break the assumption that tuple is immutable.
>
> That's what I see, am I right in that?
>
> Thanks!
>
> On Wed, Aug 2, 2017 at 4:07 PM, Alan Gauld via Tutor <tutor@python.org>
> wrote:
>
>> On 02/08/17 20:01, C W wrote:
>>
>> > I am a little confused about why Tuple can be sorted.
>> >
>> > Suppose I have the following,
>> >
>> >> aTuple = (9, 3, 7, 5)
>> >> sorted(aTuple)
>> > [3, 5, 7, 9]
>>
>> sorted() returns a new object.
>> The original tuple has not been changed
>>  - print aTuple to confirm this.
>>
>> HTH
>> --
>> 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
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] What exactly does the three dots do? Why such as thing?

2017-08-09 Thread C W
Dear Python experts,

What exactly does the three dots do?
> aList = ...
> type(pList)
ellipsis

It's an ellipsis, a spot holder to later. But what data type is it: vector,
matrix?

In every other language, you initialize a variable you want to use. What's
the point of ellipsis?

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


Re: [Tutor] If tuple cannot be sorted, then why sorted() on a tuple is fine?

2017-08-03 Thread C W
As pointed out by someone else, ?sorted
sorted(iterable, key=None, reverse=False)

It seems like the only requirement is iterable. I guess tuple is iterable,
so, it doesn't break the assumption that tuple is immutable.

That's what I see, am I right in that?

Thanks!

On Wed, Aug 2, 2017 at 4:07 PM, Alan Gauld via Tutor <tutor@python.org>
wrote:

> On 02/08/17 20:01, C W wrote:
>
> > I am a little confused about why Tuple can be sorted.
> >
> > Suppose I have the following,
> >
> >> aTuple = (9, 3, 7, 5)
> >> sorted(aTuple)
> > [3, 5, 7, 9]
>
> sorted() returns a new object.
> The original tuple has not been changed
>  - print aTuple to confirm this.
>
> HTH
> --
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] If tuple cannot be sorted, then why sorted() on a tuple is fine?

2017-08-02 Thread C W
Dear list,

I am a little confused about why Tuple can be sorted.

Suppose I have the following,

> aTuple = (9, 3, 7, 5)
> sorted(aTuple)
[3, 5, 7, 9]

Why is it ok to sort a the class tuple? If it is invariant by nature, then
wouldn't applying a function on it yield an error?

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


Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-27 Thread C W
Thank you very much, Steve!

I think I got it. To get help() on a method, you have to somehow invoke an
object first.

In your example, even an empty vector [] will do.

Thanks!

On Wed, Jul 26, 2017 at 10:16 PM, Steven D'Aprano <st...@pearwood.info>
wrote:

> On Wed, Jul 26, 2017 at 10:03:59PM -0400, C W wrote:
> > Thank you very much, all!
> >
> > One other question: how do you look up a method?
>
> Any of these will work:
>
> help(list.sort)
>
> help([].sort)
>
> alist = [1, 2, 3, 99]
> help(alist.sort)
>
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-27 Thread C W
Thank you very much, all!

One other question: how do you look up a method?

>help(sort)
Traceback (most recent call last):

  File "", line 1, in 
help(sort)

NameError: name 'sort' is not defined


Back to function vs method, I came from R:

aList = sort(aList)

There was never aList.sort(), I was fine with it for years. I suppose
sort(aList) is more of a data science thing.

Thanks to all!


On Wed, Jul 26, 2017 at 8:21 PM, Steven D'Aprano <st...@pearwood.info>
wrote:

> On Wed, Jul 26, 2017 at 02:40:17PM -0400, C W wrote:
>
> > sorted(aList)
> > > [2, 3, 4, 5]
>
> sorted() makes a copy of whatever you give it, as a list, and sorts the
> copy. It doesn't have to be a list to start with:
>
> py> sorted("alphabet")
> ['a', 'a', 'b', 'e', 'h', 'l', 'p', 't']
>
>
> > aList.sort()
> > aList
> > > [2, 3, 4, 5]
>
> The sort() method only works on actual lists, and it sorts the list in
> place, just as list.reverse() reverses the list, list.append() appends a
> value to the list, list.insert() inserts a value into the list, etc.
>
> > Why is there both? They do the same thing. Is if I unknowingly hit the
> > keyboard with the aList.sort(), then the "damage" is permanent.
>
> They don't do the same thing. sorted() makes a copy of the argument
> first, list.sort() does not.
>
> We have both because sometimes one is useful and other times the other
> is useful. Originally, and for many years, Python only had list.sort(),
> and if you wanted to sort a copy you had to write:
>
> blist = list(alist)
> blist.sort()
>
> which is always a minimum of two lines and not very convenient. So it
> was eventually decided to add sorted().
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] What's the difference between sort(aList) and aList.sorted()

2017-07-26 Thread C W
Dear Python experts,

I suppose I have the following Python code:

aList = [3, 5, 2, 4]

sorted(aList)
> [2, 3, 4, 5]

aList.sort()

aList
> [2, 3, 4, 5]

My understanding of each is:
1) function(variable) is manipulating a vector, I can do bList =
sorted(aList)
2) object.method() is permanently changing it, I don't even need to assign
it in #1.

Why is there both? They do the same thing. Is if I unknowingly hit the
keyboard with the aList.sort(), then the "damage" is permanent.

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


Re: [Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-18 Thread C W
I come back to report that after trying it myself. Rodeo is the winner!
Spyder came close.

There's even a post on moving the layouts around just like RStudio.
http://discuss.yhat.com/t/move-around-the-layout/43

I hope they implement that soon. Thanks everyone for your advice!

On Thu, Jun 8, 2017 at 9:00 PM, Cameron Simpson  wrote:

> On 02Jun2017 18:14, Mats Wichmann  wrote:
>
>> Sadly, vim, which is The Best Editor Ever (see 23 million flamewars for
>> why such statement can only be a feeble attempt at humor, not reality),
>> is now trying to behave like an IDE, and it's doing things badly wrong.
>> For example, if I type import in a "from" line, it helpfully inserts the
>> word import... meaning those end up with syntax errors, "from foo import
>> import bar".  I don't know who is responsible for that idiocy and
>> haven't taken the time to figure out how to shut off the misbehavior.
>>
>
> I'm sure it can be turned off; mine doesn't do this. I also turned off the
> auto-comment-continuation.
>
> Anyway, somewhat off topic.
>
> -- Cameron Simpson 
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-08 Thread C W
Indeed, just installed it. Rodeo is a very close to RStudio.

My review:
It looks like Rodeo is still in earlier development stage, despite look
alike, many features in RStudio don't exist in Rodeo.

It lacks a keyboard configuration. Cmd + Enter combo works! It runs the
current line of code, this will make up for all else. Hence, my hope is not
lost.

Overall:
If you are used to RStudio and Matlab, this is the closest you will see. I
am happy to discovery it. Thanks, Monte!


To the earlier replies, and my opinion:
Atom does not do line by line evaluation, you must compile it yourself, you
can't modify things in Console, but re-run script. (I have tried on someone
else's computer)

IPython is great for presentation, but you need to start it up in Terminal,
copy paste localhost address. You need to restart it if you are using it
for Python 2 vs Python 3. Great, but tedious to work with. (I have it)

Spyder does not have an icon in Application, you again need to start it up
in Terminal with a few commands. It is slow to start up. (I have it)

On Thu, Jun 8, 2017 at 1:42 PM, Monte Milanuk  wrote:

> Have you looked at Rodeo (https://www.yhat.com/products/rodeo)?  The UI
> looks a *lot* like R-Studio (for a reason)...
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-02 Thread C W
Dear Python list,

I am an R user learning Python. What is a good editor?

1) Pycharm
PyCharm evaluates the entire script, I just want to change a few lines in
the script.
For example,

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1,0.1)
y = np.sin(2 * np.pi * x)

plt.figure(1)
plt.clf()
plt.plot(x, y)
plt.show()

Now, I want to do a scatter plot, but don't want to generate the data
again. I just want the "line by line" evaluation like in R and Matlab.
Basically, you can type in console and add to the existing variables.

2) Spyder
Spyder looks a lot like RStudio, I like it! But, it does not have an app
icon in applications.  I am baffled. I do ~/anaconda/bin/spyder every time.

Am I missing something or is this the way it is?

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


Re: [Tutor] Counting a string backwards

2017-05-29 Thread C W
Wow, that's the best explanation I've seen so far, now it's gonna stick
with me!

Thank you!

On Sun, May 28, 2017 at 10:00 PM, Steven D'Aprano <st...@pearwood.info>
wrote:

> On Sun, May 28, 2017 at 01:58:22PM -0400, C W wrote:
> > Dear Python list,
> >
> > I am having trouble understanding the following.
> [...]
>
>
> The way to think about string indexing and slicing is that the index
> positions mark *between* the characters. Take your string:
>
> Machine learning is awesome!
>
> For brevity, I'll just use the first word:
>
> Machine
>
> Imagine slicing it between the characters. I'll mark the cuts with a
> vertical bar:
>
> |M|a|c|h|i|n|e|
>
> and add indexes. The indexes will only line correctly if you use a
> monspaced or fixed width font like Courier, otherwise things may not
> line up correctly.
>
> |M|a|c|h|i|n|e|
> 0 1 2 3 4 5 6 7
>
> Here they are again starting from the right, I've spread things out a
> bit to fit in the minus signs:
>
>|M  |a  |c  |h  |i  |n  |e  |
>-7  -6  -5  -4  -3  -2  -1  0
>
> Notice that 0 gets used twice. Of course, that's impossible, because it
> would be ambiguous. If you give 0 as an index, how does Python know
> whether you mean 0 at the start or 0 or the end? So the simple rule
> Python uses is that 0 *always* means the start.
>
> When you give a single index, Python always uses the character
> immediately to the right of the cut:
>
> s = "Machine"
> s[0]
> => returns "M"
>
> s[-1]
> => returns "e"
>
> s[7]
> => raises an exception, because there is no character to the right
>
> When you give two indexes, using slice notation, Python returns the
> characters BETWEEN those cuts:
>
> s[0:7]
> => returns "Machine"
>
> s[1:-1]
> => returns "achin"
>
> Because 0 always means the start of the string, how do you slice to the
> end? You can use the length of the string (in this case, 7) or you can
> leave the ending position blank, and it defaults to the length of the
> string:
>
> s[1:]  # means the same as [1:len(s)]
>
> You can leave the starting position blank too, it defaults to 0:
>
> s[:]  # means the same as [0:len(s)]
>
> So remember that slices always cut *between* the index positions.
>
>
> Things get complicated when you include a step (or stride), especially
> when the step is negative. For step sizes other than 1, it is
> probably best to think of looping over the string:
>
> py> s = "Nobody expects the Spanish Inquisition!"
> py> s[-1:1:-2]
> '!otsun snp h tex db'
>
> is somewhat like:
>
> for i in range(len(s)-1, 1, -2):
> print s[i]
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Counting a string backwards

2017-05-29 Thread C W
Hi Alan

Thank you very much, I got it. So in this case, there is no need to specify
where it ends.

In fact, even if I wanted to specify the ending, I can't!

Thank you!

On Sun, May 28, 2017 at 7:19 PM, Alan Gauld via Tutor <tutor@python.org>
wrote:

> On 28/05/17 18:58, C W wrote:
>
> > Now if I do case 2,
> >> print(great[-3:-1])
> >> me
> >
> > Where did the exclamation mark go in case 2?
> >
> > I was told the count begins at zero, that's true going forward, but not
> > backwards.
>
> Its not about where the count starts its about where it finishes.
> It finishes 1 item before the second index. so in this case
> you get the items at -3 and -2.
>
> If you specify a third parameter you can change the
> direction of the count thus:
>
> >>> great[-1:-3:-1]
> '!e'
>
> So now you get the characters at -1 and -2 (ie in reverse order)
>
> If you want them in original order starting at -3 just omit
> the -1:
>
> >>> great[-3:]
> 'me!'
>
> HTH,
>
> --
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Counting a string backwards

2017-05-28 Thread C W
Dear Python list,

I am having trouble understanding the following.

If I do case 1,
great = "Machine learning is awesome!"
> print(great[-1])
> !

Now if I do case 2,
> print(great[-3:-1])
> me

Where did the exclamation mark go in case 2?

I was told the count begins at zero, that's true going forward, but not
backwards.

What is wrong?

Thank you!

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