link to the HP 3115 iPAQ - list of features for info -- $350 w/Bluetooth built-in

2005-06-02 Thread val
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=5778810554&ssPageName=MER
C_VIC_ReBay_Pr4_PcY_BIN


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


Re: list of functions question

2006-04-27 Thread val
John Machin wrote:
> On 27/04/2006 10:38 AM, val bykoski wrote:
> > Hi The List:
> >   I have a modeling app where i'm detecting events (in temporal
> > dynamics) applying a set of (boolean) functions - kind of:
> >
> > event_list = "f1 f2 etc".split()  # each fi detects a specific event
> > i have defs for functions fi, or simple boolean expressions for each, so
> > that evList is a list of defs or boolean expressions
> > for ev in evList:
> >if ev:# this supposedly is a call ev(t)
> >   # doing smth with the event
> >
> >I didn't succeed, though, (blindly) trying various options.
> > I thought/tried "apply()" but couldn't get it work.
> > I'd appreciate pointers to how to handle this kind of
> > functions or events lists (or objects?) and how to call those
> > functions in a loop.
> >thanks,val
>
> This may be something like what you are trying to achieve:
>
> # untested
> def fx(arg):
>  pass
> def fy(arg):
>  pass
> def fdefault(arg):
>  pass
>
> funcmap = {
> 'x1': fx,
> 'x2': fx,
> 'y' : fy,
> }
>
> eventlist = "y x2 x2 x1 y".split()
> for ev in eventlist:
>      efunc = funcmap.get(ev, fdefault)
>  if efunc(t): # what is t
>  # do something

John,
Thanks alot.  It does work with the fx, fy,etc as (boolean)
expressions.
And it is faster vs. using defs.
Thanks again, the great list...
Val

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


Re: list of functions question

2006-04-27 Thread val
Hi Kent,
Thanks.  Great help.  It does work now,
and with expressions as well.
my very best,
Val

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


Re: list of functions question

2006-04-27 Thread val
Tim,
Greatly appreciate your help.  You are right - the functions work
from the list;  i don't actually need the string with events.
Thanks again - great list and great people...
Val

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


easy_install of module produces un-importable result

2008-12-08 Thread Val
I've written my first module, "gpsparser" and uploaded it as an egg to
PyPI. I can use easy_istall to install my own module, but when I try
to import it I get an ImportError "No module named gpsparser".

So I've done some research and found that in my site-packages/
directory gpsparser exists as an egg file, while all the other
packages I've installed exist as an egg directory.

If this makes any sense, can anyone explain what I've done wrong in
building my package that the installation process does not unpack the
egg file?

Thanks,

Val
--
http://mail.python.org/mailman/listinfo/python-list


Re: easy_install of module produces un-importable result

2008-12-08 Thread Val
On Dec 8, 2:57 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Val schrieb:> I've written my first module, "
>
> " and uploaded it as an egg to
>
> > PyPI. I can use easy_istall to install my own module, but when I try
> > to import it I get an ImportError "No module named gpsparser".
>
> > So I've done some research and found that in my site-packages/
> > directory gpsparser exists as an egg file, while all the other
> > packages I've installed exist as an egg directory.
>
> > If this makes any sense, can anyone explain what I've done wrong in
> > building my package that the installation process does not unpack the
> > egg file?
>
> This has nothing to do with that - it's simply that your egg is empty.
> Take a look at this:
>
> (gpsparser)mac-dir:Application Support deets$ unzip -l
> /Users/deets/.virtualenvs/gpsparser/lib/python2.5/site-packages/gpsparser-0 
> .0.1-py2.5.egg
> Archive:
> /Users/deets/.virtualenvs/gpsparser/lib/python2.5/site-packages/gpsparser-0 
> .0.1-py2.5.egg
>    Length     Date   Time    Name
>              
>          1  12-08-08 12:04   EGG-INFO/dependency_links.txt
>        249  12-08-08 12:04   EGG-INFO/PKG-INFO
>        599  12-08-08 12:04   EGG-INFO/SOURCES.txt
>          1  12-08-08 12:04   EGG-INFO/top_level.txt
>          1  12-08-08 11:25   EGG-INFO/zip-safe
>                      ---
>        851                   5 files
> (gpsparser)mac-dir:Application Support deets$
>
> I presume you miss a
>
>      packages=find_packages(),
>
> line in your setup.py, with
>
> from setuptools import setup, find_packages
>
> to actually get the find_packages.
>
> Diez

You are absolutely right. How embarrassing. Thank you SO much!

-Val
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python component model

2006-10-13 Thread val bykoski
Peter Wang wrote:
> Edward,
> 
> This isn't in response to any specific one of the 100+ posts on this
> thread, but I justed wanted to encourage you to continue your
> investigation into Python component models and maybe looking for some
> common ground between them.  Frequently the individual developers are
> too heads-down on working on their own things to do a broad survey, so
> I think this would be very useful indeed.
> 
> I wouldn't have felt it necessary to post this except for the large
> number of posts along the lines of "foo.dict is introspective enough
> for me!".  I think you might have an easier time evangelizing the
> principle of component-oriented programming (or "event-based", or
> "reactive", or whatever) if you separated it from the notions of RAD UI
> development.  There is a very large difference between writing
> components and writing objects, and it seems that most people arguing
> "python doesn't need components" don't see this distinction.
> 
> For me, it's the difference between writing "live" objects and "dead"
> objects.  Live objects not only encapsulate implementations of an
> interface with some state, but they also encapsulate handling of
> events, i.e. responses to changes in their environment.  Dead objects
> have methods but there has to be a function somewhere that knows which
> dead object to call with what parameters at exactly the right time.
> (The only mechanism for managing this complexity is to create ever more
> functions at ever higher levels of abstraction, or to have a
> proliferation of nebulously-defined "manager" objects.)  IMHO once you
> cross this chasm and are able to model your problem domain with live
> objects that go off and automatically respond to the runtime
> environment and Do the Right Thing, it's very hard to go back to a dead
> object mindset.  I can understand, however, that until one makes this
> leap, it might seem like an academic and useless distinction.
> 
> -peter
> 
Excellent post, Peter.  Thanks for great clarification. Looking from a
physicist' perspective, im always trying to compare/evaluate languages
from "the physical reality/dynamics" angle.  So, the run-time
space/dynamics is the only one that matches the natural "always-runtime"
objects - atoms, molecules, EM fields, biological cells(?).  It is the
*reactive* world with event/forces-driven dynamics.  Seemingly, there is
nothing beyond that, including biology.

The essential feature of that runtime world is the persistence or (in
physical terms) the built-in memory/storage mechanism (soft degrees of
freedom), so that an event (and response to it) changes the object.  The
persistence is obvious in biology, but also is very important in
(bio)molecular dynamics.   From that physics/QM angle, a generic
("always-live") object  which learns the environment (by building *and
updating* its responses) seems to be a quite adequate representation for
a real physical object.  But this seems to be already available in
Python, right?

The Enthought' Traits that describes (physical) properties and their
dynamics seems to be a critically important component of that vision,
and i admire the Enthought' people vision and practical efforts.  Keep
on and good luck!
run-time-ly, y'rs

Val
Air Force Research Lab
Hanscom AFB, MA
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: excellent book on information theory

2006-01-22 Thread val bykoski
Anton Vredegoor wrote:
> Paul Rubin wrote(>>):

[...]

> All of the books writers seem to have not caught up with the idea of
> hyperlinks and continue to dwell in neolithical paper dreams :-)
> 
> If they only woke up and let someone like me write some Visual Python
> code to illustrate the algorithms or even let me just write Python
> implementations of the algorithms to accompany the books, I'd probably
> have work for years to come.
> 
> 
>>Math is a beautiful subject, and is not at all secret or inaccessible.
>>Try to broaden your horizons a bit ;-).
> 
> 
> I hope you're not trying to outexpertize me. You seem to be thinking
> that you know more about math than me, probably because you have a
> formal education in the subject?
> 
> If so, you're proving my point, and thank you very much.
> 
> Anton
> 

Well, to me it is not a matter of formal education, or math, or Python.
There should be a *fresh thought/idea* how to handle the unknown 
reality.  The existing (formal) language, being helpful, was created 
hundreds years ago and of course needs an update.  But again, the point 
is not a new tool, even very flexible like Python.  I think the *direct* 
sensor/data-driven techniques based on parsing/understanding 
observations (images, fields, etc) might be a step in promising 
direction.  Any thoughts?

respectful-ly y'rs,
val
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some thougts on cartesian products

2006-01-23 Thread val bykoski
Christoph Zwerschke wrote:
> Bryan Olson schrieb:
> 
>>> Still think there is no such thing?
>>
>>
>> Uh, yes.
>>
>>The Cartesian product of two sets A and B (also called the
>>product set, set direct product, or cross product) is defined to
>>be the set of [...]
>>
>> All sets, no strings. What were you looking at?
> 
> 
> Not only sets. This goes on (anyway "everything is a set"). You can also 
> have the Cartesian product of functions. And you can think of a string 
> as a function from a countable index set I to the set of all characters 
> C. So the Cartesian product of two strings will become a function from 
> IxI to CxC. Since IxX is countable again, this is equivalent to a tuple 
> of 2-tuples of characters which you can also interpret as a tuple of 
> strings with 2 chars:
> 
> "ab" x "cd" = ("ac", "ad", "bc", "bd")
> 
> Do I have eliminated all remaining clarities now? :-)
> 
> -- Christoph

Christoph,
i think you raised a great issue: a lack of efficient support for 
"combining" objects.  Any language, if has smth to do with reality,
needs that kind of functionality.The combination dynamics, or growth 
(multiplication) dynamics is a critically important functionality in 
chemistry, physics, biology.  It probably may be emulated by standard 
means such as lists and dictionaries.  If such support is available 
though, this is a sign of mature language designed to cover the 
realistic processes with rich growth/combination dynamics.
For instance, the dynamics of aperiodic growth that generates a 3D 
aperiodic arrays/structures with the controllable "bits" in each unit to 
be configured by dynamic masks to match the environmental ("boundary") 
conditions would be a significant step in building next-generation 
languages/silicon to support synthesis of realistic 3D structures (and 
functions).  Accordingly, the command "line" may need to be 2D and the 
interpreter be designed to handle/understand not only a (command) text.
Just reflecting aloud..
val
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python advocacy in scientific computation

2006-03-06 Thread val bykoski
sturlamolden wrote:
> Robert Kern wrote:
> 
>> 1. Write grant proposals.
>> 
>> 2. Advise and teach students.
> 
> 
> Sorry I forgot the part about writing grant applications. As for 
> teaching students, I have thankfully not been bothered with that too 
> much.
> 
>> Yes, and this is why you will keep saying, "My simulation is
>> running too slowly," and "My simulation is running out of memory."
>> All the vectorization you do won't make a quadratic algorithm run
>> in O(n log(n)) time. Knowing the right algorithm and the right data
>> structures to use will save you programming time and execution
>> time. Time is money, remember, and every hour you spend tweaking 
>> Matlab code to get an extra 5% of speed is just so much grant money
>> down the drain.
> 
> 
> Yes, and that is why I use C (that is ISO C99, not ANSI C98) instead
> of Matlab for everything except trivial tasks. The design of Matlab's
>  language is fundamentally flawed. I once wrote a tutorial on how to 
> implement things like lists and trees in Matlab (using functional 
> programming, e.g. using functions to represent list nodes), but it's 
> just a toy. And as Matlab's run-time does reference counting insted
> of proper garbage collection, any datastructure more complex than
> arrays are sure to leak memory (I believe Python also suffered from
> this as some point). Matlab is not useful for anything except
> plotting data quickly. And as for the expensive license, I am not
> sure its worth it. I have been considering a move to Scilab for some
> time, but it too carries the burden of working with a flawed
> language.
> 

A quick addition to Robert's very reasonable response to you.  My point 
is that to *trust* a simulation *results* (no matter how fast/slow/etc 
you obtained it) you have to explore and manage the "physics" or 
"biology" of your code.  That's where Python's readability, flexibility, 
and dynamism (including on-the-fly model building/testing/correction) as 
well as model introspecting and exploration capabilities are of critical 
importance and sometimes the indication to a missing link.  It does not 
hurt to remember that the original idea (by S.Ulam) of a computer was 
the idea of an *experimentation environment* (including sampling).  It 
does not look like the Matlab's strongest point is the feedback-driven 
experimentation.  Or i'm missing smth about ISO C99?
  Val Bykoski
-- 
http://mail.python.org/mailman/listinfo/python-list


list of functions question

2006-04-26 Thread val bykoski
Hi The List:
   I have a modeling app where i'm detecting events (in temporal 
dynamics) applying a set of (boolean) functions - kind of:

event_list = "f1 f2 etc".split()  # each fi detects a specific event
i have defs for functions fi, or simple boolean expressions for each, so 
that evList is a list of defs or boolean expressions
for ev in evList:
if ev:  # this supposedly is a call ev(t)
   # doing smth with the event

I didn't succeed, though, (blindly) trying various options.
I thought/tried "apply()" but couldn't get it work.
I'd appreciate pointers to how to handle this kind of
functions or events lists (or objects?) and how to call those
functions in a loop.
thanks,val  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast and easy GUI prototyping with Python

2008-06-21 Thread Val-Amart
On 21 июн, 15:36, [EMAIL PROTECTED] wrote:
> Which tools would you use? I want the interface design to be as easy
> and fast as possible, all ideology aside. I'm considering either
> IronPython+Visual Studio or Python+Qt -- but I'm open for other
> suggestions.
>
> Visual Studio seems to offer the easiest solution, but is IronPython
> stable enough? How easy is the IronPython/Visual Studi integration?
> What about IronPython Studio?

Use PyQt. You will gain great portability +all the functionality built
in qt.
You can try PyGTK also, though i wont recommend it.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Terminating processes on Windows (handles and IDs)

2008-06-23 Thread Val-Amart
On Jun 23, 6:33 pm, geoffbache <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I've always wondered why os.kill isn't supported on Windows. I found a
> discussion somewhere from 2006 about this so it seems others have
> wanted it, but still nothing. So I have a half-baked solution
> involving calling "taskkill" on Windows Vista or "tskill" on Windows
> XP via the shell. I feel there has to be a better way.
>
> I'm also fairly confused about when I've got an ID and when I've got a
> handle. The subprocess module gives me IDs which the above programs
> accept, but other ways of spawning processes give me process handles
> (while referring to them as process IDs in the docs...) and I don't
> know how to kill a process with these. Besides, I've found an
> amazingly useful PyGTK method, gobject.child_watch_add, which does
> exactly what I want on UNIX but wants process handles on Windows. So I
> can't use it in conjunction with subprocess there, and if I use some
> other way of spawning processes I can't clean them up later.
>
> Is there any way to convert one of these numbers to the other? Or to
> get a process handle out of subprocess?
> (There must be one down there somewhere, surely?)
>
> Sorry for rambling a bit, am confused.
>
> Regards,
> Geoff Bache

My way to do it is using excellent wmi module by Tim Golden, which
relies on Mark Hammond's pywin32 and Windows native wmi functionality.
Here is the link - http://tgolden.sc.sabren.com/python/wmi.html
Maybe, there is a more elegant way of doing that, but it works for me,
and i feel nice with wmi.
--
http://mail.python.org/mailman/listinfo/python-list


key and ..

2016-11-17 Thread Val Krem via Python-list


Hi all,
Sorry for asking such a basic question butI am trying  to merge two files(file1 
and file2) and do some stuff. Merge the two files by the first column(key). 
Here is the description of files and what I would like to do.


file1

key c1   c2
1  759   939
2  345 154571
3  251 350711
4 3749  22159
5  676  76953
6   46756


file2
key  p1p2
1   759939
2   345 154571
3   251 350711
4  3915  23254
5  7676  77953
7   256   4562

create file3
a) merge the two files by (key) that exit in  file1 and file2
b) create two variables dcp1 = c1- p1 and dcp2= c2-p2
c) sort file3 by dcp2(descending) and output

create file4:-  which exist in file1 but not in file2
create file5:-  that exist in file2 but not in file1;


Desired output files

file3
key   c1c2 p1  p2 dcp1   dcp2
4   3749  22159  3915  23254  -166  -1095
5676  76953  7676  77953 -7000  -1000
1759939   759939 0  0
2345 154571   345 154571 0  0
3251 350711   251 350711 0  0

file4
key c1   p1
6   46   756

file5
key p1   p2
7  256  4562



Thank you in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


data frame

2016-12-23 Thread Val Krem via Python-list
Hi all,

#!/usr/bin/env python
import sys
import csv
import numpy as np
import pandas as  pd

a= pd.read_csv("s1.csv")
print(a)

 size   w1   h1
0  512  214   26
1  123  250   34
2  234  124   25
3  334  213   43
4  a45  223   32
5  a12  214   26

I wanted to create a new column by adding the two column values 
as follows

a['test'] = a['w1'] + a['h1']

Traceback (most recent call last):
File 
"/data/apps/Intel/intelpython35/lib/python3.5/site-packages/pandas/indexes/base.py",
 line 2104, in get_loc
return self._engine.get_loc(key)
File "pandas/index.pyx", line 139, in pandas.index.IndexEngine.get_loc 
(pandas/index.c:4152)
File "pandas/index.pyx", line 161, in pandas.index.IndexEngine.get_loc 
(pandas/index.c:4016)
File "pandas/src/hashtable_class_helper.pxi", line 732, in 
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13153)
File "pandas/src/hashtable_class_helper.pxi", line 740, in 
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13107)
KeyError: 'w1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "tt.py", line 16, in 
a['test']=a['w1'] + a['h1']

File "pandas/src/hashtable_class_helper.pxi", line 740, in 
pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13107)
KeyError: 'w1'

Can someone help me what the problem is?

Thank you in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: data frame

2016-12-23 Thread Val Krem via Python-list
Here is the first few lines of the data


s1.csv 
size,w1,h1
512,214,26
123,250,34
234,124,25
334,213,43

and the script

a=pd.read_csv("s1.csv", skipinitialspace=True).keys()
print(a)
i see the following

Index(['size', 'w1', 'h1'], dtype='object')



when I wanted to add the two columns; then I get the following message.

a=pd.read_csv("s1.csv", skipinitialspace=True).keys()
a['test']=a['w1'] + a['h1']
print(a)




data/apps/Intel/intelpython35/lib/python3.5/site-packages/pandas/indexes/base.py:1393:
 VisibleDeprecationWarning: using a non-integer number instead of an integer 
will result in an error in the future
return getitem(key)
Traceback (most recent call last):
File "tt.py", line 12, in 
a['test']=a['w1'] + a['h1']
File 
"/data/apps/Intel/intelpython35/lib/python3.5/site-packages/pandas/indexes/base.py",
 line 1393, in __getitem__
return getitem(key)
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis 
(`None`) and integer or boolean arrays are valid indices



On Friday, December 23, 2016 3:09 PM, Peter Otten <__pete...@web.de> wrote:
Val Krem via Python-list wrote:

> Hi all,
>
> #!/usr/bin/env python
> import sys
> import csv
> import numpy as np
> import pandas as  pd
>
> a= pd.read_csv("s1.csv")
> print(a)
>
>  size  w1  h1
> 0  512  214  26
> 1  123  250  34
> 2  234  124  25
> 3  334  213  43
> 4  a45  223  32
> 5  a12  214  26
>
> I wanted to create a new column by adding the two column values
> as follows
>
> a['test'] = a['w1'] + a['h1']
>
> Traceback (most recent call last):
> File
> "/data/apps/Intel/intelpython35/lib/python3.5/site-
packages/pandas/indexes/base.py",
> line 2104, in get_loc return self._engine.get_loc(key) File
> "pandas/index.pyx", line 139, in pandas.index.IndexEngine.get_loc
> (pandas/index.c:4152) File "pandas/index.pyx", line 161, in
> pandas.index.IndexEngine.get_loc (pandas/index.c:4016) File
> "pandas/src/hashtable_class_helper.pxi", line 732, in
> pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13153)
> File "pandas/src/hashtable_class_helper.pxi", line 740, in
> pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13107)
> KeyError: 'w1'
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "tt.py", line 16, in 
> a['test']=a['w1'] + a['h1']
>
> File "pandas/src/hashtable_class_helper.pxi", line 740, in
> pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:13107)
> KeyError: 'w1'
>
> Can someone help me what the problem is?
>
> Thank you in advance

Have a look at a.keys(). I suspect that the column name has extra space:

>>> pd.read_csv("s1.csv").keys()
Index([u'size', u' w1', u' h1'], dtype='object')

I that's what you see you can fix it by reading the csv with
skipinitialspace=True:

>>> pd.read_csv("s1.csv", skipinitialspace=True).keys()
Index([u'size', u'w1', u'h1'], dtype='object')


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


/data/apps/Intel/intelpython35/lib/python3.5/site-packages/pandas/indexes/base.py:1393:
 VisibleDeprecationWarning: using a non-integer number instead of an integer 
will result in an error in the future
return getitem(key)
Traceback (most recent call last):
File "tt.py", line 12, in 
a['test']=a['w1'] + a['h1']
File 
"/data/apps/Intel/intelpython35/lib/python3.5/site-packages/pandas/indexes/base.py",
 line 1393, in __getitem__
return getitem(key)
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis 
(`None`) and integer or boolean arrays are valid indices







On Friday, December 23, 2016 3:09 PM, Peter Otten <__pete...@web.de> wrote:
Val Krem via Python-list wrote:

> Hi all,
> 
> #!/usr/bin/env python
> import sys
> import csv
> import numpy as np
> import pandas as  pd
> 
> a= pd.read_csv("s1.csv")
> print(a)
> 
>  size   w1   h1
> 0  512  214   26
> 1  123  250   34
> 2  234  124   25
> 3  334  213   43
> 4  a45  223   32
> 5  a12  214   26
> 
> I wanted to create a new column by adding the two column values
> as follows
> 
> a['test'] = a['w1'] + a['h1']
> 
> Traceback (most recent call last):
> File
> "/data/apps/Intel/intelpython35/lib/python3.5/site-
packages/pandas/indexes/base.py",
>

Re: data frame

2016-12-24 Thread Val Krem via Python-list
Thank you Peter and  Christ.
It is was a white space and the fix fixed it.
Many thanks.




On Friday, December 23, 2016 5:26 PM, Peter Otten <__pete...@web.de> wrote:
Val Krem via Python-list wrote:

> Here is the first few lines of the data
> 
> 
> s1.csv
> size,w1,h1
> 512,214,26
> 123,250,34
> 234,124,25
> 334,213,43

Did you put these lines here using copy and paste? The fix below depends on 
the assumption that your data is more like

size, w1, h1
512, 214, 26
123, 250, 34
...

> a=pd.read_csv("s1.csv", skipinitialspace=True).keys()

You should use the keys() method call for diagnosis only. The final script 
that might work if your problem is actually space after the commas is

import pandas as  pd

a = pd.read_csv("s1.csv", skipinitialspace=True)
a["test"] = a["h1"] + a["w1"]
print(a)


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


data

2016-12-29 Thread Val Krem via Python-list
Hi all,
I have a sample of data set and would  like to summarize in the following way.


ID,class,y
1,12,10
1,12,10
1,12,20
1,13,20
1,13,10
1,13,10
1,14,20
2,21,20
2,21,20
2,21,10
2,23,10
2,23,20
2,34,20
2,34,10
2,35,10

I want  get  the total count by ID, and the  the number of classes
by ID. The y variable is either 10 or 20 and count each by iD

The result should look like as follows.

ID,class,count,10's,20's
1,3,7,4,3
2,4,8,4,4

I can do this in  two or more steps. Is there an efficient way of doing it?


I used 

pd.crosstab(a['ID'],a['y'],margins=True)
and got

ID,10's,20's all
1,4,3,7
2,4,4,8

but I want get the class count as well like as follows

ID,class,10's,20's,all
1,3,4,3,7
2,4,4,4,8

how do I do it in python?
thank you in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


crosstab output

2017-01-06 Thread Val Krem via Python-list
Hi all,

How do I access the rows and columns of a data frame crosstab output?


Here is code using  a sample data and output.

a= pd.read_csv("cross.dat", skipinitialspace=True)
xc=pd.crosstab(a['nam'],a['x1'],margins=True)

print(xc)

x10  1 
nam 
A13  2 
A21  4

I want to create a variable  by adding 2/(3+2) for the first row(A1)
and 4/(1+4) for the second row (A2)

Final data frame would be
A1 3 2  0.4
A2 1 4  0.8

Thank you in advance
-- 
https://mail.python.org/mailman/listinfo/python-list


Read and count

2016-03-10 Thread Val Krem via Python-list
Hi all,

I am a new learner about python (moving from R to python) and trying  read and 
count the number of observation  by year for each city.


The data set look like
city year  x 

XC1 2001  10
XC1   2001  20
XC1   2002   20
XC1   2002   10
XC1 2002   10

Yv2 2001   10
Yv2 2002   20
Yv2 2002   20
Yv2 2002   10
Yv2 2002   10

out put will be

city
xc1  2001  2
xc1   2002  3
yv1  2001  1
yv2  2002  3


Below is my starting code
count=0
fo=open("dat", "r+")
str = fo.read();
print "Read String is : ", str

fo.close()


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


Re: Read and count

2016-03-10 Thread Val Krem via Python-list
Thank you very much for the help.

First I want count by city and year. 
City year count
Xc1.2001.  1
Xc1.2002.  3
Yv1. 2001.  1
Yv2.2002.  4
This worked fine !

Now I want to count by city only
City. Count
Xc1.   4
Yv2.  5

Then combine these two objects with the original data and send it to a file 
called  "detout" with these columns:

"City", " year ", "x ", "cycount ", "citycount"

Many thanks again






This worked fine. I tried to count only by city  and combine the three objects 
together 

City
Xc1  4
Yv2  5



Sent from my iPad 

> On Mar 10, 2016, at 3:11 AM, Jussi Piitulainen 
>  wrote:
> 
> Val Krem writes:
> 
>> Hi all,
>> 
>> I am a new learner about python (moving from R to python) and trying
>> read and count the number of observation by year for each city.
>> 
>> 
>> The data set look like
>> city year  x 
>> 
>> XC1 2001  10
>> XC1   2001  20
>> XC1   2002   20
>> XC1   2002   10
>> XC1 2002   10
>> 
>> Yv2 2001   10
>> Yv2 2002   20
>> Yv2 2002   20
>> Yv2 2002   10
>> Yv2 2002   10
>> 
>> out put will be
>> 
>> city
>> xc1  2001  2
>> xc1   2002  3
>> yv1  2001  1
>> yv2  2002  3
>> 
>> 
>> Below is my starting code
>> count=0
>> fo=open("dat", "r+")
>> str = fo.read();
>> print "Read String is : ", str
>> 
>> fo.close()
> 
> Below's some of the basics that you want to study. Also look up the csv
> module in Python's standard library. You will want to learn these things
> even if you end up using some sort of third-party data-frame library (I
> don't know those but they exist).
> 
> from collections import Counter
> 
> # collections.Counter is a special dictionary type for just this
> counts = Counter()
> 
> # with statement ensures closing the file
> with open("dat") as fo:
># file object provides lines
>next(fo) # skip header line
>for line in fo:
># test requires non-empty string, but lines
># contain at least newline character so ok
>if line.isspace(): continue
># .split() at whitespace, omits empty fields
>city, year, x = line.split()
># collections.Counter has default 0,
># key is a tuple (city, year), parentheses omitted here
>counts[city, year] += 1
> 
> print("city")
> for city, year in sorted(counts): # iterate over keys
>print(city.lower(), year, counts[city, year], sep = "\t")
> 
> # Alternatively:
> # for cy, n in sorted(counts.items()):
> #   city, year = cy
> #   print(city.lower(), year, n, sep = "\t")
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Different sources of file

2016-03-14 Thread Val Krem via Python-list


Hi all,



I am made a little progress on using python.
I have five files to read from different sources  and concatenate them to one 
file.  From each file I want only to pick  few column  (x1, x2  and  x3). 
However, these columns say x3 was  a date in one file it was recorded as a 
character  (2015/12/26)  and in the other file it was records  (20151226)  and 
in the other file it was recorded as  (26122015). How do I standardized these 
into one form (mmdd-20151126). If there is no date then delete that record

2. The other variable x2. In one of the one files it was recorded as  "M" and 
"F". In the other  file  x3  is  1 for male and 2 for female.  So I want to 
change  all to 1 or 2. if this variable is out of range M / F or 1 or 2 then 
delete that record

3.  After doing all these I want combine all files into one  and send it to 
output. 

Finally, do some statistics  such as number of records read from each file. 
Distribution of sex  and total number of records sent out to a file.

Below is my attempt but not great
#!/usr/bin/python
import sys
import csv
from collections import Counter

N=10
count=0
with open("file1") as f1:
for line in f1:
count+=1
print("Total Number of records read", count)
# I want to see the first few lines of the data


file1Name   x2x3
Alex1  F   2015/02/11
Alex2  M   2012/01/27
Alex3  F   2011/10/20
Alex4  M   .
Alex5  N   2003/11/14

file2
Name  x2x3
Bob1  1   2010-02-10
Bob2  2   2001-01-07
Bob3  1   2002-10-21
Bob4  2   2004-11-17
bob5  0   2009-11-19

file2
Namex2x3
Alexa1  0   12102013
Alexa2  2   20012007
Alexa3  1   11052002
Alexa4  2   26112004
Alexa5  2   15072009

Output to a file 
Name x2  x3
Alex1   2   20150211
Alex2   1   20120127
Alex3   2   20111020
Bob11   20100210
Bob22   20010107
Bob31   20021021
Bob42   20041117
Alexa2  2   20070120
Alexa3  1   20020511
Alexa4  2   20041126
Alexa5  2   20090715
-- 
https://mail.python.org/mailman/listinfo/python-list


file -SAS

2016-03-19 Thread Val Krem via Python-list
Hi all,

I am trying to read sas7bdat file using the following



from sas7bdat import SAS7BDAT

with SAS7BDAT('test.sas7bdat') as f:
for row in f:
 print row   ### I want print the first 10 row. how can I do that?


I got error message of 


from sas7bdat import SAS7BDAT
ImportError: No module named sas7bdat

What did I miss?
Val
-- 
https://mail.python.org/mailman/listinfo/python-list


course

2017-06-19 Thread Val Krem via Python-list
Hi all,

Is there  on line course in Python? I am looking for a level between beginner 
and intermediate. I would appreciate if you could  suggest me?

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