[Tutor] Data frame packages

2011-03-31 Thread Ben Hunter
Is anybody out there familiar with data frame modules for python that will
allow me to read a CSV in a similar way that R does? pydataframe and
DataFrame have both befuddled me. One requires a special stripe of R that I
don't think is available on windows and the other is either very buggy or
I've put it in the wrong directory / installed incorrectly. Sorry for the
vague question - just taking the pulse. I haven't seen any chatter about
this on this mailing list.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Data frame packages

2011-03-31 Thread Ben Hunter
I appreciate all the responses and apologize for not being more detailed. An
R data frame is a tightly grouped array of vectors of the same length. Each
vector is all the same datatype, I believe, but you can read all types of
data into the same variable. The benefit is being able to quickly subset,
stack and such (or 'melt' and 'cast' in R vernacular) according to any of
your qualitative variables (or 'factors'). As someone pretty familiar with R
and quite a newbie to python, I'm wary of insulting anybody's intelligence
by describing what to me is effectively the default data format my most
familiar language. The following is some brief R code if you're curious
about how it works.

d - read.csv(filename, header = TRUE, sep = ',') #this reads the table.
'-' is the assignment operator
d[ , 'column.name'] # this references a column name. This same syntax can be
used to reference all rows (index is put left of the comma) and columns in
any order.

The data frame then allows you to quickly declare new fields as functions of
other fields.
newVar - d[ ,'column.name'] + d[ ,'another.column']
d$newVar - newVar # attaches newVar to the rightmost column of 'd'

At any rate, I finally got pydataframe to work, but had to go from Python
2.6 to 2.5. pydataframe has a bug for Windows that the author points out.
Line 127 in 'parsers.py' should be changed from:
columns = list(itertools.izip_longest(*split_lines ,fillvalue = na_text))

to:
columns = list(itertools.izip_longest(list(*split_lines),fillvalue =
na_text))

I don't know exactly what I did, but the module would not load until I did
that. I know itertools.izip_longest requires 2 arguments before fillvalue,
so I guess that did it.

It's a handy way to handle alpha-numeric data. My problem with the csv
module was that it interpreted all numbers as strings.

Thanks again.

On Thu, Mar 31, 2011 at 8:17 AM, James Reynolds eire1...@gmail.com wrote:



 On Thu, Mar 31, 2011 at 11:10 AM, Blockheads Oi Oi 
 breamore...@yahoo.co.uk wrote:

 On 31/03/2011 09:38, Ben Hunter wrote:

 Is anybody out there familiar with data frame modules for python that
 will allow me to read a CSV in a similar way that R does? pydataframe
 and DataFrame have both befuddled me. One requires a special stripe of R
 that I don't think is available on windows and the other is either very
 buggy or I've put it in the wrong directory / installed incorrectly.
 Sorry for the vague question - just taking the pulse. I haven't seen any
 chatter about this on this mailing list.



 What are you trying to achieve?  Can you simply read the data with the
 standard library csv module and manipulate it to your needs?What makes
 you say that the code is buggy, have you examples of what you tried and
 where it was wrong?  Did you install with easy_install or run setup.py?



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


 Regards.

 Mark L.



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















 I'm not familiar with it, but what about http://rpy.sourceforge.net/

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


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


Re: [Tutor] Problem recognizing '{' character?

2011-03-29 Thread Ben Hunter
Thanks a ton. For the record I did read the 'command' module help page, but
must have skipped over the 'Platforms: Unix' and 'Deprecated' parts. I
successfully got it to work with the subprocess module, but I really
appreciate you filling out the rest with the sys.stderr.write(stderrdata). I
certainly would have stumbled over that.

-BJH


On Mon, Mar 28, 2011 at 8:12 PM, Ben Hunter bjameshun...@gmail.com wrote:

 Hi,

 I'm completing the Python lessons on YouTube that Google posted. At the end
 of section 2 of day 2, there is a task to identify files then put them in a
 zip file in any directory. The code is from the 'solution' folder, so it's
 not something I wrote. I suspect I have a problem with PATHS or environment
 variables. I'm new to programming in something as advanced as Python, but I
 do okay with VBA - so I just feel like there's a setting up issue somewhere.
 I'm on Windows 7, tried running this in Idle and from the command line.

 These two work perfectly.

 def get_special_paths(dirname):
   result = []
   paths = os.listdir(dirname)  # list of paths in that dir
   for fname in paths:
 match = re.search(r'__(\w+)__', fname)
 if match:
   result.append(os.path.abspath(os.path.join(dirname, fname)))
   return result


 def copy_to(paths, to_dir):
   if not os.path.exists(to_dir):
 os.mkdir(to_dir)
   for path in paths:
 fname = os.path.basename(path)
 shutil.copy(path, os.path.join(to_dir, fname))

 This third one does not.

 def zip_to(paths, zipfile):
   Zip up all of the given files into a new zip file with the given
 name.
   cmd = 'zip -j ' + zipfile + ' ' + ' '.join(paths)
   print Command I'm going to do: + cmd
   (status, output) = commands.getstatusoutput(cmd)
   # If command had a problem (status is non-zero),
   # print its output to stderr and exit.
   if status:
 sys.stderr.write(output)
 sys.exit(1)

 My command is this:  copyspecial.zip_to(paths, 'zippy')

 But something goes wrong and it spits this out:
 '{' is not recognized as an internal or external command,
 operable program or batch file.


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


[Tutor] Problem recognizing '{' character?

2011-03-28 Thread Ben Hunter
Hi,

I'm completing the Python lessons on YouTube that Google posted. At the end
of section 2 of day 2, there is a task to identify files then put them in a
zip file in any directory. The code is from the 'solution' folder, so it's
not something I wrote. I suspect I have a problem with PATHS or environment
variables. I'm new to programming in something as advanced as Python, but I
do okay with VBA - so I just feel like there's a setting up issue somewhere.
I'm on Windows 7, tried running this in Idle and from the command line.

These two work perfectly.

def get_special_paths(dirname):
  result = []
  paths = os.listdir(dirname)  # list of paths in that dir
  for fname in paths:
match = re.search(r'__(\w+)__', fname)
if match:
  result.append(os.path.abspath(os.path.join(dirname, fname)))
  return result


def copy_to(paths, to_dir):
  if not os.path.exists(to_dir):
os.mkdir(to_dir)
  for path in paths:
fname = os.path.basename(path)
shutil.copy(path, os.path.join(to_dir, fname))

This third one does not.

def zip_to(paths, zipfile):
  Zip up all of the given files into a new zip file with the given
name.
  cmd = 'zip -j ' + zipfile + ' ' + ' '.join(paths)
  print Command I'm going to do: + cmd
  (status, output) = commands.getstatusoutput(cmd)
  # If command had a problem (status is non-zero),
  # print its output to stderr and exit.
  if status:
sys.stderr.write(output)
sys.exit(1)

My command is this:  copyspecial.zip_to(paths, 'zippy')

But something goes wrong and it spits this out:
'{' is not recognized as an internal or external command,
operable program or batch file.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor