last

Pyspark : forward fill with last observation for a DataFrame

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Using Spark 1.5.1, I've been trying to forward fill null values with the last known observation for one column of my DataFrame. It is possible to start with a null value and for this case I would to backward fill this null value with the first knwn observation. However, If that too complicates the code, this point can be skipped. In this post , a solution in Scala was provided for a very similar problem by zero323 . But, I don't know Scala and I don't succeed to ''translate'' it in Pyspark API code. It's possible to do it with Pyspark ?

Fill zero values of 1d numpy array with last non-zero values

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say we have a 1d numpy array filled with some int values. And let's say that some of them are 0 . Is there any way, using numpy array's power, to fill all the 0 values with the last non-zero values found? for example: arr = np.array([1, 0, 0, 2, 0, 4, 6, 8, 0, 0, 0, 0, 2]) fill_zeros_with_last(arr) print arr [1 1 1 2 2 4 6 8 8 8 8 8 2] A way to do it would be with this function: def fill_zeros_with_last(arr): last_val = None # I don't really care about the initial value for i in range(arr.size): if arr[i]: last_val = arr[i] elif last

Calculate the last day of the quarter

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What's the most efficient way to calculate the last day of the prior quarter? Example: given the date 11/19/2008, I want to return 9/30/2008. Platform is SQL Server 回答1: If @Date has the date in question Select DateAdd(day, -1, dateadd(qq, DateDiff(qq, 0, @Date), 0)) EDIT: Thanks to @strEagle below, simpler still is: Select dateadd(qq, DateDiff(qq, 0, @Date), -1) 回答2: Actually simpler is: SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), -1) 回答3: Get the current date SELECT CONVERT(DATE,GETDATE()) [Current Date] Get the 1st date of the quarter

Coin change(Dynamic programming)

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a question about the coin change problem where we not only have to print the number of ways to change $n with the given coin denominations for eg {1,5,10,25}, but also print the ways For example if the target = $50, and the coins are {1,5,10,25} , then the ways to actually get use the coins to get the target are 2 × $25 1 × $25 + 2 × $10 + 1 × $5 etc. What is the best time complexity we could get to solve this problem? I tried to modify the dynamic programming solution for the coin change problem where we only need the

Index numpy nd array along last dimension

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Is there an easy way to index a numpy multidimensional array along the last dimension, using an array of indices? For example, take an array a of shape (10, 10, 20) . Let's assume I have an array of indices b , of shape (10, 10) so that the result would be c[i, j] = a[i, j, b[i, j]] . I've tried the following example: a = np . ones (( 10 , 10 , 20 )) b = np . tile ( np . arange ( 10 ) + 10 , ( 10 , 1 )) c = a [ b ] However, this doesn't work because it then tries to index like a[b[i, j], b[i, j]] , which is not the same as a[i, j,

trie浅谈

南楼画角 提交于 2019-12-03 01:21:16
关于trie ​ 其实字典树和以上两种算法有很大不同,但是hash由于其优秀的应用,导致有些字符串查找用hash也是可行的. ​ 字典树中支持添加,查找,区间查询(可持久化字典树),而且在异或操作上有更加好的操作; 前置知识 ​ 树的基本构造; 入坑 ​ 字典树是通过动态建点,而形成的树,基本数组有两维, \(tr[x][to]\) 中第一维存的是节点标号,而第二维存的是当字符为 \(to\) 时通向的节点; 基本操作 ​ 我当时入门是学的是 这道题 ; 给你一些初始字符串,询问,给你一个字符串,这个字符串在这个初始字符串中是否存在 ​ 当时使用hash写的,但是没过; ​ 现在我们可以用字典树先存一下初始字符串,然后在树上匹配,单次时间复杂度 \(O(n)\) ; code #include<bits/stdc++.h> using namespace std; int n,m,trie[300007][27],num[300007],sz; bool vis[300007]; void build(char a[]){ int now=0; for(int i=0;i<strlen(a);i++){ if(!trie[now][a[i]-'a']) trie[now][a[i]-'a']=++sz; now=trie[now][a[i]-'a']; } num[now]++;

Python 3 Finding the last number in a string

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How can I find the last number in any big string? For eg in the following string I want 47 as the output: 'tr bgcolor="aa77bb"td>font face="verdana"color="white" size="2">b>Total/b>/font>/td>\td>font face="verdana"color="white" size="2">b>47/b>/font>/td>/tr>' PS: We don't know the number. The number 47 is just an example. It can be any number from 0 to 900. 回答1: >>> import re >>> text = 'tr bgcolor="aa77bb"td>font face="verdana"color="white" size="2">b>Total/b>/font>/td>\td>font face="verdana"color="white" size="2">b>47/b>/font>/td

Get last li on a line jQuery

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: We have a simple ul <ul> <li> some text </li> <li> some some text </li> <li> text more </li> <li> text here </li> </ul> ul { text-align: center; width: 100px; } li { width: auto; display: inline; } So the ul can have several lines. How do I take last li of the each line inside ul ? 回答1: If by last li on the each line of the ul you mean the last li in each ul , then: $ ( 'ul li:last-child' ); However, if you mean that you have your li 's within the same ul written up on several lines in your source code, and you now want to get the

Get Last Monday in Spark

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Spark 2.0 with the Python API. I have a dataframe with a column of type DateType(). I would like to add a column to the dataframe containing the most recent Monday. I can do it like this: reg_schema = pyspark.sql.types.StructType([ pyspark.sql.types.StructField('AccountCreationDate', pyspark.sql.types.DateType(), True), pyspark.sql.types.StructField('UserId', pyspark.sql.types.LongType(), True) ]) reg = spark.read.schema(reg_schema).option('header', True).csv(path_to_file) reg = reg.withColumn('monday', pyspark.sql.functions.when

last version of NodeJS install by apt-get

匿名 (未验证) 提交于 2019-12-03 01:19:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Debian Linux (Debian Stable, UBUNTU LTS, etc.) and others use apt-get as good and reliable installer tool. I need to use only apt-get ... The problem is that I do the simple sudo apt-get install nodejs but as result I have nodejs --version (or node --version ) 0.10.41 (!) It is not the today's most updated stable Node.JS version , 5.2.0 I also try node -p process.versions.v8 that results in 3.14.5.9 so, also is very less than 5.2 . NOTES I am using UBUNTU 14 LTS.... And try a workaround but not works, sudo apt-get remove --purge nodejs sudo