I using Python 3.2 and have a dictionary
>>> d = {0:[1,2], 1:[1,2,3], 2:[1,2,3,4]}
whose values are lists I would like to zip into a list of tuples. If I
explicitly write:
>>> list(zip([1,2], [1,2,3], [1,2,3,4])
[(1, 1, 1), (2, 2, 2)]
I get exactly what I want. On the other hand, I have tried
>
Thank you everyone, for your input. The help is much appreciated.
Thomas Philips
--
http://mail.python.org/mailman/listinfo/python-list
I have coded a robust (Theil-Sen) regression routine which takes as
inputs two lists of numbers, x and y, and returns a robust estimate of
the slope and intercept of the best robust straight line fit.
In a pre-processing phase, I create two new lists, x1 and y1; x1 has
only the unique values in x,
I have a simulation that runs many times with different parameters,
and I want to aggregate the output into a single file with one rub: I
want a header to be written only the first time. My program looks a
bit like this:
def main():
for param in range(10):
simulate(param)
def simulat
On Aug 26, 7:23 pm, Emile van Sebille <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I have a list that starts with zeros, has sporadic data, and then has
> > good data. I define the point at which the data turns good to be the
> > first index with a non-zero entry that is followed by a
I have a list that starts with zeros, has sporadic data, and then has
good data. I define the point at which the data turns good to be the
first index with a non-zero entry that is followed by at least 4
consecutive non-zero data items (i.e. a week's worth of non-zero
data). For example, if my lis
I've just bought an iMac (OS X 10.5.2, will almost immediately jump to
10.5.3), and am looking to install Python on it, and to use it with
XCode, Apple's IDE. Some googling suggests that a number of people
have had trouble getting Python to run satisfactorily on their Macs.
This is my first Mac, an
I have just installed R and Rpy, and am experiencing an odd problem
when driving R from Python - if I create a plot in R, the portion of
the plot window that lies under the IDLE window in which I type my
Python code remains blank. So if I type
>>> from rpy import *
>>> x = range(10)
>>> y = [i **
Thanks a mill - works like a charm!
--
http://mail.python.org/mailman/listinfo/python-list
I'm running Python 2.5.2 on Windows XP and need to interface with R,
so I downloaded the R 2.6.2 statistical package and installed it, and
did the same for RPy 1.02 (i made sure I got the version for Python
2.5 and R 2.62.). When I go to the Python command line and type
>>> from rpy import *
I get
Paul, George,
Thanks a mill - the help is greatly appreciated.
Thomas Philips
--
http://mail.python.org/mailman/listinfo/python-list
To keep a simulation tidy, I created a dispatcher that generates
random variables drawn from various distributions as follows:
import random
RVType = 1 #Type of random variable - pulled from RVDict
RVDict= {'1': random.betavariate(1,1), '2': random.expovariate(1),
'3': rand
I imported two modules (random and matplotlib), and found that the
functions available to me from the random module depended on the order
in which the imports occured. In particular, if I import random first,
none of its functions seem to be available, while if I import it after
matplotlib, I seem
To pretty up some numbers stored as strings, I used locale to format
them with commas. I then found the following error:
>>> import locale
>>>locale.setlocale(locale.LC_ALL, 'English_United States.1252')
'English_United States.1252'
>>> locale.format('%d', float('2244012500.'), grouping = Tr
Mike,
Thanks for the pointers. I looked through the ASPN cookbook, but found
a more reliable (and easier to implement) way to get the files I want.
I downloaded GNU Wget from http://users.ugent.be/~bpuype/wget/( the
current version is 1.10.2), and then ran it from Python as follows
import os
rc =
Our systems administrator suggested that I try wget, a GNU utility
that is designed to pick up data. It might prove to be the easiest way
to get the data I want, and I am going to try that first.
Thanks again.
Thomas Philips
--
http://mail.python.org/mailman/listinfo/python-list
I'd like to download data from the website
http://www.russell.com/Indexes/performance/daily_values_US.asp. On
this web page, there are links to a number of .csv files, and I'd like
to download all of them automatically each day. The file names are not
visible on the page, but if I click on a link,
John,
I'd be delighted to try xlwt (does it work under Python 2.4 and 2.5?)
I followed the link to ...svn/xlwt/trunk and found a collection of
files, but no Windows installer. How do I install xlwt?
Thanks in advance
Thomas Philips
--
http://mail.python.org/mailman/listinfo/python-list
My program creates three lists: the first has dates expressed as
strings, the second has floats that are strictly positive, and the
third has floats that are strictly negative. I have no trouble writing
the data in these lists to a .csv file using the csv module using the
following code.
outfile =
Thanks for the insights. I solved the problem as follows: I created a
new class method called cleanUp, which resets NStocks to an empty list
and N1 to 0. Works like a charm - it's the first time I've used a
class method, and I immediately see its utility. Thanks again
class Stock(object):
NSto
On May 9, 5:25 pm, [EMAIL PROTECTED] wrote:
> To test some theories, I created a new class variable, an int named
Diez,
Thanks. It is for precisely this reason that I added another class
variable - the immutable int N1. But this too keeps getting
incremented on subsequent calls to simulation( ). I
To test some theories, I created a new class variable, an int named
N1, which is not mutable. So my Stock class now looks as follows:
class Stock(object):
NStocks = [] #Class variables
N1 = 0
def __init__(self, id, returnHistory):
self.id = id
self
I have written a program that runs portfolio simulations with
different parameters and prints the output, but am mystified by the
behavior of a mutable class variable. A simplified version of the
program follows - would you kindly help me understand why it behaves
the way it does.
The function mai
Thanks - you have covered a fair bit of gorund here - I will modify
myRange taking your suggestions into account. The one suggestion that
I'm going to have to think through is repeatedly incrementing res.
I deliberately did not use this as repeated addition can cause
rounding errors to accumulate,
I need to create ranges that can start and end with real numbers.
Searching this newsgroup brought me to a function that I then modified
as follows:
def myRange(iMin, iMax=None, iStep=1):
"""Extends range to real numbers. Wherever possible, use Python's
range .
In other cases, make the
Instead of starting IDLE as I normally do, I started the Python
interpreter and tried to run a program. I got a Python prompt (>>>),
and then tried unsuccessfully to run a Python script named Script1.py
that runs perfectly well in IDLE. Here's what I did:
>>>Script1.py
Traceback (most recent call
For any list x, x.index(item) returns the index of the FIRST
occurrence of the item in x. Is there a simple way to identify the
LAST occurrence of an item in a list? My solution feels complex -
reverse the list, look for the first occurence of the item in the
reversed list, and then subtract its in
I have an ordered list e.g. x = [0, 100, 200, 1000], and given any
positive integer y, I want to determine its appropriate position in
the list (i.e the point at which I would have to insert it in order to
keep the list sorted. I can clearly do this with a series of if
statements:
if yx[i] for i i
Thanks a mill - os.path.getctime(f) is what I needed. Unfortunately, my
attempts to turn the integer it returns into a date have failed.
>>> os.path.getctime(fn)#fn was created today, 1/17/2007
1168955503
I tried to convert this to a date object by typing
>>>datetime.date.fromordinal(1168955
I'd like to create a list of all files in a directory that were created
after a certain date. How does one do this? I've used glob.glob to
create a list of all files whose name matches a substring, but I don't
see how I can use it to identify files by their creation date.
Thanks in advance for the
What you really want to write is
for i in x:
for j in i:
print j
The outer loop iterates over the tuples in the list, while the inner
loop iterates over the elements of each tuple. So j (in your example)
is always an integer, and is therefore unsubscriptable, which is
exactly what the
I'm trying to optimize a function using SciPy's optimize.fmin, but am
clearly getting the syntax wrong, and would be grateful for some
guiidance. First, here's the function
def func(Y,x):
"""Y holds samples of a function sampled at t=-3,-2,-1,0,1,2,3.
Y[3]=0 always.
func return
I'm looking forward to the release IronPython, primarily for its IDE. I
currently use scipy and pyExcelerator to crunch numbers and write them
to Excel: does can these packages be used with IronPython as well?
Thanks in advance
Thomas Philips
--
http://mail.python.org/mailman/listinfo/python-li
I write data to Excel files using PyExcelerator 0.6.3.a and have done
so successfully for small files (10-15 cells). I'm experiencing an
error when writing a big chunk of data (10,000 cells) to Excel. By way
of comparison, the same data writes perfectly well to a csv file using
Python's built in cs
John,
I had spelled PyExcelerator with a capital P, but it worked just fine.
I then checked the directory it was installed in, and found it read
C:\Python24\Lib\site-packages\PyExcelerator. As soon as I changed the
directory name to C:\Python24\Lib\site-packages\pyExcelerator, my
programs stopped
I use PyExcelerator to write data into Excel files, and repeatedly call
the function writeData with different filenames fn from my main
routine. Unfortunately, only one file - the last one - is created. The
problem seems to lie with the fact that I do not close the existing
file before calling the
This is just what the doctor ordered. Thanks, as always, everyone!
> By breaking out of the while loop as shown above.
>
> Peter
--
http://mail.python.org/mailman/listinfo/python-list
I create list of files, open each file in turn, skip past all the blank
lines, and then process the first line that starts with a number (see
code below)
filenames=glob.glob("C:/*.txt")
for fn in filenames:
f =file(fn)
line = " "
while line[0] not in digits:
line = f.next()
Thank you, everyone, for resolving my question. At one point, while
trying to solve the problem, I typed
>>> y[1,3]
Traceback (most recent call last):
File "", line 1, in ?
TypeError: list indices must be integers
The error message gave me no clue as to what I was doing wrong (in my
mind, I was
I have a list y
>>>y
['20001201', 'ARRO', '04276410', '18.500', '19.500', '18.500',
'19.500', '224']
from which I want to extract only the 2nd and 4th item by partially
unpacking the list. So I tried
>>>a,b = y[2,4]
Traceback (most recent call last):
File "", line 1, in ?
TypeError: list indices
I have just installed PyExcelerator, and now want to use it to read
Excel spreadsheets with a variable number of rows and columns and with
multiple sheets. Unfortunately, no documentation seems to accompany
PyExcelerator. Does anyone know of a good source of documentations
and/or examples? The auth
Thanks!!! I had a good laugh at myself after i got it working.
--
http://mail.python.org/mailman/listinfo/python-list
I downloaded PyExcelerator.zip as I need to write some data into Excel
files, and tried unsuccessfully to install it. I unzipped the files
into C:/Python24/Lib/site-packages/PyExcelerator, and in a python
command line window typed
>>>os.chdir("C:/Python24/Lib/site-packages/PyExcelerator")
followe
I expected the following code to work:
f = file(fn,"wb")
writer = csv.writer(f)
for i in range(IMax):
writer.writerow([dates[i]].append([ReturnHistories[j][i] for j in
range(N)]))
but instead i got the following error message:
Error: sequence expected
However, if i modify the code to read
w
I want to create a list of lists, each of which is identical, but which
can be modified independently i.e:
>>>x = [ [0], [0], [0] ]
>>> x[0].append(1)
>>> x
[[0, 1], [0], [0]]
The above construct works if I have only few items, but if I have many,
I'd prefer to write
>>> N =3
>>> x =N*[[0]]
>>> x
Tested it and it works like a charm! Thank you very much for fixing
this. Not knowing what an SVN is, I simply copied the code into the
appropriate library files and it works perfectly well.
May I suggest a simple enhancement: modify corrcoef so that if it is
fed two 1 dimensional arrays, it retur
I want to compute the correlation between two sequences X and Y, and
tried using SciPy to do so without success.l Here's what I have, how
can I correct it?
>>> X = [1, 2, 3, 4, 5]
>>> Y = [5, 4, 3, 2, 1]
>>> import scipy
>>> scipy.corrcoef(X,Y)
Traceback (most recent call last):
File "", line 1,
I installed SciPy and NumPy (0.9.5, because 0.9.6 does not work with
the current version of SciPy), and had some teething troubles. I looked
around for help and observed that the tutorial is dated October 2004,
and is not as thorough as Python's documentation. Is there an
alternative source of info
I have written a number of functions and stored them in a file named
myFunctions.py. This keeps all my functions under one roof, and if I
want to use or one or more of them in a program, I can start the
program off with
from myFunctions import f1,f2
Some of these functions require various math ro
I use Python to generate a huge amount of data in a .csv file which I
then process using Excel. In particular, I use Excel's solver to solve
a number of non-linear equation, and then regress the results of
hundreds of calls to Solver against a set of known values, enabling me
to calibrate my model.
Right now my code reads as follows:
infile=file(FileName)
for line in reversed(infile.readlines()): #Search from the bottom up
if int(line.split()[0]) == MyDate:
Data= float(line.split()[-1])
break
infile.close()
I have to read about 10,000 files, each with data. I'm l
I have a text file with many hundreds of lines of data. The data of
interest to me, however, resides at the bottom of the file, in the last
20 lines. Right now, I read the entire file and discard the stuff I
don't need. I'd like to speed up my program by reading only the last 20
lines. How do I do
Thanks for the help. I now understand it better. As Bruno points out, I
really don't need a property in this case, as my attribute is public,
and I will remove it.
Thomas Philips
--
http://mail.python.org/mailman/listinfo/python-list
I have a class with a name attribute, which I want to modify using
property.The following code works just fine:
class Portfolio(object):
def __init__( self, name="Port1"):
self.name=name
def getname(self):
return self._name
def setname(self,newname="Port2"):
Thank you all so much for the generous dollop of help: the dictionary
suggestion is particularly helpful. The problem arises as follows: A
software application stores the securities held in a portfolio in a
.csv file, one row per security, with three colulmns.
The first has a security identifier o
I have list of lists of the following form
L=[['A', 100], ['B', 300], ['A', 400], ['B', -100]]
I want to aggregate these lists, i.e. to reduce L to
L=[['A', 500], ['B', 200]] #500 = 100+400, 200=300-100
Here's how I have done it:
L.sort()
for i in range(len(L),0,-1):
if L[i-1][0]=L[i][0]:
I have a Python program that collects user input using
msg = "Enter the full path and name of the file to be processed: "
answer = raw_input(msg)
If I run it in IDLE, the question is splashed across the execution
window, and if it is long, simply wraps to the next line. Most
importantly, it is in
I've just downloaded and installed ActivePython and am trying to
customize the PythonWin editor. Its line spacing seems to default to 2,
and consequently, I cannot see many lines of code on a screen. How do I
set the line spacing to 1?
Thomas Philips
--
http://mail.python.org/mailman/listinfo/py
58 matches
Mail list logo