About Messages on Installs

2019-06-25 Thread Eray Erdin
Greetings, dear community members,

I sometimes use npm and, in the installation process, some packages throw
messages regarding to warnings or info/survey URLs.

I wish to use something similar in a package I maintain. Is it possible to
print some data to users' terminal in the installation process? Even if so,
would it be considered a good practice?

Many thanks in advance.

Eray Erdin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Understand workflow about reading and writing files in Python

2019-06-25 Thread DL Neil

On 25/06/19 11:50 AM, Windson Yang wrote:
DL Neil > 于2019年6月24日周一 上午11:18写道:

Yes, better to reply to list - others may 'jump in'...
On 20/06/19 5:37 PM, Windson Yang wrote:
 > Thank you so much for you review DL Neil, it really helps :D.
However,
 > there are some parts still confused me, I replyed as below.
It's not a particularly easy topic...
 > DL Neil mailto:[email protected]>
 > >> 于2019年6月19日周三 下午
2:03写道:

...


...there are so many ways one can mess-up!
 >     I like your use of the word "shift", so I'll continue to use it.
 >     There are three separate units of data to consider - each of
which
 >     could
 >     be called a "buffer". To avoid confusing (myself) I'll only
call the
 >     'middle one' that:
 >     1 the unit of data 'coming' from the data-source
 >     2 the "buffer" you are implementing
 >     3 the unit of data 'going' out to a data-destination.
 >
 > Just to make it clear, when we use `f.write('abc')` in python,
(1) means
 > 'abc', (2) means the buffer handle by Python (by default 8kb),
(2) means
 > the file *f* we are writing to, right?
Sorry, this is my typo, (3) means the file *f* we are writing to, right?


Correct.
- to avoid exactly this sort of confusion it is best NOT to use short 
names but to (carefully) choose meaningful variable-names!


How about:
1 "input_file" (I'd prefer to add context, eg "expenses_file")
and
3 "output_file" (again... "expenses_summary")



No! (sorry) f.write() is an output operation, thus nr3.

"f" is not a "buffer handle" but a "file handle" or more accurately a
"file object".

When we:

         one_input = f.read( NRbytes )

(ignoring EOF/short file and other exceptions) that many bytes will
'appear' in our program labelled as "one_input".

However, the OpSys may have read considerably more data, depending upon
the device(s) involved, the application, etc; eg if we ask for 2 bytes
the operating system will read a much larger block (or applicable unit)
of data from a disk drive.

The same applies in reverse, with f.write( NRbytes/byte-object ), until
we flush or close the file.

Those situations account for nr1 and nr3. In the usual case, we have no
control over the size of these buffers - and it is best not to meddle!

I agreed with you.

Hence:-

 >     1 and 3 may be dictated to you, eg hardware or file
specifications,
 >     code
 >     requirements, etc.
 >
 >     So, data is shifted into the (2) buffer in a unit-size
decided by (1) -
 >     in most use-cases each incoming unit will be the same size, but
 >     remember
 >     that the last 'unit' may/not be full-size. Similarly, data
shifted out
 >     from the (2) buffer to (3).
 >
 >     The size of (1) is likely not that of (3) - otherwise why use a
 >     "buffer"? The size of (2) must be larger than (1) and larger
than (2) -
 >     for reasons already illustrated.
 >
 > Is this a typo? (2) larger than (1) larger than (2)?

Correct - well spotted! nr2 > nr1 and nr2 > nr3


When we run 'f.write(100', I understand why nr2 (by defaut 8kb) > nr1 
(100), but I'm not sure why nr2 > nr3 (file object) here?


The program's internal string or data-structure MUST be as large or 
larger than the output size.


If the output file requires three fields of four kilobytes each, that's 
12KB. If the internal buffer is only 1KB in length, how will it satisfy 
the 12KB specification?


That said, a classic 'out by one' error. The earlier text should have 
said "len(nr2) >= len(nr3)"!




 >     I recall learning how to use buffers with a series of
hand-drawn block
 >     diagrams. Recommend you try similarly!

Try this!


 >     Now, let's add a few critiques, as requested (interposed below):-
 >
 >
 >     On 19/06/19 3:53 PM, Windson Yang wrote:t
 >      > I'm trying to understand the workflow of how Python
read/writes
 >     data with
 >      > buffer. I will be appreciated if someone can review it.
 >      >
 >      > ### Read n data
 >
 >     - may need more than one read operation if the size of (3)
"demands"
 >     more data than the size of (1)/one "read".
 >
 >
 > Looks like the size of len of one read() depends on
 >

https://github.com/python/cpython/blob/master/Modules/_io/bufferedio.c#L1655 ?


You decide how many bytes should be read. That's how much will be
transferred from the OpSys' I/O into the Python program's space. With
the major exception, that if there is no (more) data available, it is
defined as an exception (EOF = end of file) or if there are fewer bytes
of data than requested (in which

pandas split and melt()

2019-06-25 Thread Sayth Renshaw
Hi

Having fun with pandas filtering a work excel file.
My current script opens selected and filters the data and saves as excel.

import pandas as pd 
import numpy as np

log = pd.read_excel("log_dump_py.xlsx")
df = log.filter(items=['Completed', 'Priority', 'Session date', 'Consultant', 
'Coach',
   'Delivery Method', 'Focus of Coaching', 'Leader', 'Site',
   'Coaching Description','Motor/Property', 
   ],)
completed_tasks = df.loc[(df['Completed'] == 'Yes') & (df['Motor/Property'] == 
'Motor') & (df['Delivery Method'] == 'Group Coaching')]
print(completed_tasks.head(n=5))
completed_tasks.to_excel("filtered_logs.xlsx")

This leaves me with a set of several columns. The main column of concern for 
this example is a consultant

Session dateConsultant
2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE, 
Colem;#17230;

How can I split the consultant column, keep only names and drop the numbers and 
for every session date create a line with data and consultants name?

NB. There are varied amounts of consultants so splitting across columns is 
uneven. if it was even melt seems like it would be good 
https://dfrieds.com/data-analysis/melt-unpivot-python-pandas


Thanks

Sayth


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pandas split and melt()

2019-06-25 Thread DL Neil

On 26/06/19 6:13 PM, Sayth Renshaw wrote:

Hi
Having fun with pandas filtering a work excel file.
My current script opens selected and filters the data and saves as excel.

...


This leaves me with a set of several columns. The main column of concern for 
this example is a consultant
Session dateConsultant
2019-06-21 11:15:00 WNEWSKI, Joan;#17226;#BALIN, Jock;#18139;#DUNE, 
Colem;#17230;

How can I split the consultant column, keep only names and drop the numbers and 
for every session date create a line with data and consultants name?
NB. There are varied amounts of consultants so splitting across columns is 
uneven. if it was even melt seems like it would be good 
https://dfrieds.com/data-analysis/melt-unpivot-python-pandas


Keep it simple: https://docs.python.org/3.6/library/string.html

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: pandas split and melt()

2019-06-25 Thread Sayth Renshaw


> > NB. There are varied amounts of consultants so splitting across columns is 
> > uneven. if it was even melt seems like it would be good 
> > https://dfrieds.com/data-analysis/melt-unpivot-python-pandas
> 
> Keep it simple: https://docs.python.org/3.6/library/string.html
> 
> -- 
> Regards =dn

I have managed to split but not filter the numbers. All other code being the 
same.
...
completed_tasks = df.loc[(df['Completed'] == 'Yes') & (df['Motor/Property'] == 
'Motor') & (df['Delivery Method'] == 'Group Coaching')]
completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = 
";")
pattern = "\\#d"
completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = 
";")
completed_tasks['Consultant'] = 
completed_tasks['Consultant'].str.contains(pattern)
...

Works without the regex which causes this error AttributeError: Can only use 
.str accessor with string values, which use np.object_ dtype

pattern = "\\#d"
completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = 
";")

Sayth
-- 
https://mail.python.org/mailman/listinfo/python-list