[Tutor] Get a single random sample

kitty kitty.a1000 at gmail.com
Fri Sep 9 12:44:10 CEST 2011


Hi,

I'm new to python and I have read through the tutorial on:
http://docs.python.org/tutorial/index.html
which was really good, but I have been an R user for 7 years and and am
finding it difficult to do even basic things in python, for example I want
to import my data (a tab-delimited .txt file) so that I can index and select
a random sample of one column based on another column. my data has
2 columns named 'area' and 'change.dens'.

In R I would just

data<-read.table("FILE PATH\\Road.density.municipio.all.txt", header=T)
#header =T gives colums their headings so that I can call each individually
names(data)
attach(data)

Then to Index I would simply:
subset<-change.dens[area<2000&area>700] # so return change.dens values that
have corresponding 'area's of between 700 and 2000

then to randomly sample a value from that I just need to
random<-sample(subset,1)


My question is how do I get python to do this???

Sorry I know it is very basic but I just cant seem to get going,

Thank you
K.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110909/d0a20884/attachment.html>


More information about the Tutor mailing list