iterate

pandas edit a cell value with itertuples

蓝咒 提交于 2019-12-06 00:10:46
I would like speed my code, so I don't like to use double for: my code: for c in range(0, n-1): for l in range(0,n-c-1): df2.ix[l,c]=C_back(l,c,df) I would like to use for x in df.itertuples(): but I don't know how to modify a specific cell value. thanks use stack for mytuple, value in df.stack().iteritems(): print(mytuple, value) consider the df df = pd.DataFrame(np.arange(9).reshape(-1, 3), list('ABC'), list('XYZ')) df for mytuple, value in df.stack().iteritems(): print(mytuple, value) ('A', 'X') 0 ('A', 'Y') 1 ('A', 'Z') 2 ('B', 'X') 3 ('B', 'Y') 4 ('B', 'Z') 5 ('C', 'X') 6 ('C', 'Y') 7 ('C

Avoiding memory leaks with Scalaz 7 zipWithIndex/group enumeratees

喜欢而已 提交于 2019-12-04 08:02:01
问题 Background As noted in this question, I'm using Scalaz 7 iteratees to process a large (i.e., unbounded) stream of data in constant heap space. My code looks like this: type ErrorOrT[M[+_], A] = EitherT[M, Throwable, A] type ErrorOr[A] = ErrorOrT[IO, A] def processChunk(c: Chunk, idx: Long): Result def process(data: EnumeratorT[Chunk, ErrorOr]): IterateeT[Vector[(Chunk, Long)], ErrorOr, Vector[Result]] = Iteratee.fold[Vector[(Chunk, Long)], ErrorOr, Vector[Result]](Nil) { (rs, vs) => rs ++ vs

Iteratees in Scala that use lazy evaluation or fusion?

爱⌒轻易说出口 提交于 2019-12-03 10:35:38
I have heard that iteratees are lazy, but how lazy exactly are they? Alternatively, can iteratees be fused with a postprocessing function, so that an intermediate data structure does not have to be built? Can I in my iteratee for example build a 1 million item Stream[Option[String]] from a java.io.BufferedReader , and then subsequently filter out the None s, in a compositional way, without requiring the entire Stream to be held in memory? And at the same time guarantee that I don't blow the stack? Or something like that - it doesn't have to use a Stream . I'm currently using Scalaz 6 but if

Can't understand Iteratee, Enumerator, Enumeratee in Play 2.0 [closed]

 ̄綄美尐妖づ 提交于 2019-12-03 04:41:12
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I have just started to learn the Play 2.0 Framework. The one thing I just can't understand is the Iteratee, Enumerator and Enumeratee

How is ReactiveMongo implemented so that it is considered non-blocking?

帅比萌擦擦* 提交于 2019-12-03 03:11:08
Reading the documentation about the Play Framework and ReactiveMongo leads me to believe that ReactiveMongo works in such a way that it uses few threads and never blocks. However, it seems that the communication from the Play application to the Mongo server would have to happen on some thread somewhere . How is this implemented? Links to the source code for Play, ReactiveMongo, Akka, etc. would also be very appreciated. The Play Framework includes some documentation about this on this page about thread pools . It starts off: Play framework is, from the bottom up, an asynchronous web framework.

Avoiding memory leaks with Scalaz 7 zipWithIndex/group enumeratees

a 夏天 提交于 2019-12-02 21:00:11
Background As noted in this question , I'm using Scalaz 7 iteratees to process a large (i.e., unbounded) stream of data in constant heap space. My code looks like this: type ErrorOrT[M[+_], A] = EitherT[M, Throwable, A] type ErrorOr[A] = ErrorOrT[IO, A] def processChunk(c: Chunk, idx: Long): Result def process(data: EnumeratorT[Chunk, ErrorOr]): IterateeT[Vector[(Chunk, Long)], ErrorOr, Vector[Result]] = Iteratee.fold[Vector[(Chunk, Long)], ErrorOr, Vector[Result]](Nil) { (rs, vs) => rs ++ vs map { case (c, i) => processChunk(c, i) } } &= (data.zipWithIndex mapE Iteratee.group(P)) The Problem

Can't understand Iteratee, Enumerator, Enumeratee in Play 2.0 [closed]

北战南征 提交于 2019-12-02 17:09:19
I have just started to learn the Play 2.0 Framework. The one thing I just can't understand is the Iteratee, Enumerator and Enumeratee pattern described in the play tutorial . I have very little experience in functional languages. What does this pattern accomplish? How does it help me write non-blocking/reactive code? some simple examples would help. The playframework 2.0 download comes with some samples. Two of which have Iteratee/Comet examples. For instance, the comet-clock sample app shows: lazy val clock = Enumerator.fromCallback { () => Promise.timeout(Some(dateFormat.format(new Date)),

Handling exceptions in an iteratee library without an error state

白昼怎懂夜的黑 提交于 2019-12-01 00:27:02
问题 I'm trying to write an enumerator for reading files line by line from a java.io.BufferedReader using Scalaz 7's iteratee library, which currently only provides an (extremely slow) enumerator for java.io.Reader . The problems I'm running into are related to the fact that all of the other iteratee libraries I've used (e.g. Play 2.0's and John Millikin's enumerator for Haskell) have had an error state as one of their Step type's constructors, and Scalaz 7 doesn't. My current implementation Here

Why does my Mapreduce implementation (real world haskell) using iteratee IO also fails with “Too many open files”

送分小仙女□ 提交于 2019-11-30 13:11:39
I am implementing a haskell program wich compares each line of a file with each other line in the file. Which can be implemented single threaded as follows distance :: Int -> Int -> Int distance a b = (a-b)*(a-b) sumOfDistancesOnSmallFile :: FilePath -> IO Int sumOfDistancesOnSmallFile path = do fileContents <- readFile path return $ allDistances $ map read $ lines $ fileContents where allDistances (x:xs) = (allDistances xs) + ( sum $ map (distance x) xs) allDistances _ = 0 This will run in O(n^2) time, and has to keep the complete list of integers in memory the whole time. In my actual

Play2 Framework proxy streaming content to client keeps connection open after streaming is done

不想你离开。 提交于 2019-11-30 07:48:08
问题 The below code does streaming back to client, in, what I gather is a more idiomatic way than using Java's IO Streams. It, however, has an issue: connection is kept open after stream is done. def getImage() = Action { request => val imageUrl = "http://hereandthere.com/someimageurl.png" Ok.stream({ content: Iteratee[Array[Byte], Unit] => WS.url(imageUrl).withHeaders("Accept"->"image/png").get { response => content } return }).withHeaders("Content-Type"->"image/png") } this is intended for