鍍金池/ 問答/ 數(shù)據(jù)分析&挖掘問答
挽歌 回答

不能重寫arraytoString方法,對于數(shù)組的操作使用 Arrays

  • Arrays.toString()
  • Arrays.deepToString() 二維數(shù)組toString
囍槑 回答
import pandas as pd
df = pd.DataFrame([['2018-3-8', 10],
    ['2018-3-9', 20],
    ['2018-3-10', 30],
    ['2018-3-11', 40],
    ['2018-3-12', 250],
    ['2018-3-13', 260],
    ['2018-3-14', 270],
    ['2018-3-15', 280]], columns=['日期', '數(shù)據(jù)1'])


def f(df):
    return (df[2] - df[1] < 100) and df[2] > df[1] and (df[1] - df[0] < 100) and df[1] > df[0] #增長大于0小于100

df[pd.rolling_apply(df, window=3, func=f)['數(shù)據(jù)1'] == True] # 滿足條件的日期(展示的是連續(xù)三天的最后一天)

判斷每個ID是否有連續(xù)3天【數(shù)據(jù)1】增長都大于0小于100的日期吧。

囍槑 回答

拷貝對象,而不是引用對象,assign與...一樣都是淺拷貝

let b = a.map(item=>{
    return Object.assign({},item)
})
笨小蛋 回答

用copy.deepcopy吧。

    Parameters
            ----------
    deep : boolean or string, default True
        Make a deep copy, including a copy of the data and the indices.
        With ``deep=False`` neither the indices or the data are copied.

        Note that when ``deep=True`` data is copied, actual python objects
        will not be copied recursively, only the reference to the object.
        This is in contrast to ``copy.deepcopy`` in the Standard Library,
        which recursively copies object data.
眼雜 回答

if(this.moduleList[1]&&this.moduleList[1]. childModuleList)

瘋浪 回答

沒想到SF有Haskell問題:)

其實(shí)你看Profiling的結(jié)果,in_rangeinherited %timeinherited %alloc都比larger_than大,占了整個程序執(zhí)行的100%和93.3%。所以第一種方法快。

寫個rewrite rule也許可以對elemenumFromTo進(jìn)行優(yōu)化。

試了寫rewrite rule,發(fā)現(xiàn)enumFromTo有inline,導(dǎo)致rewrite rule沒有生效,所以先自己實(shí)現(xiàn)一個myEnumFromTo看看效果:

module Main where

{-# RULES
   "elem/myEnumFromTo" forall (x::Integer) (n::Integer) (m::Integer) . elem x (myEnumFromTo n m) = x >= n && x <= m 
#-}

{-# NOINLINE myEnumFromTo #-}
myEnumFromTo n m
  | n == m = [n]
  | otherwise = [n] ++ myEnumFromTo (n + 1) m

main = do
  print $ {-# SCC larger_than  #-} lth 100000000
  print $ {-# scc in_range #-} inr     100000000

lth :: Integer -> Bool
lth x = (x >= 1 && x <= 65535000000000)

inr :: Integer -> Bool
inr x = let m = 65535000000000::Integer in
  x `elem` (myEnumFromTo 1 m)

Profile結(jié)果是這樣的:

main        Main             app/Main.hs:(12,1)-(14,48)    0.0   15.8


                                                                                   individual      inherited
COST CENTRE    MODULE                SRC                        no.     entries  %time %alloc   %time %alloc

MAIN           MAIN                  <built-in>                 144          0    0.0   29.6     0.0  100.0
 CAF           GHC.Conc.Signal       <entire-module>            252          0    0.0    0.9     0.0    0.9
 CAF           GHC.IO.Encoding       <entire-module>            241          0    0.0    3.8     0.0    3.8
 CAF           GHC.IO.Encoding.Iconv <entire-module>            239          0    0.0    0.3     0.0    0.3
 CAF           GHC.IO.Handle.FD      <entire-module>            231          0    0.0   47.3     0.0   47.3
 CAF           GHC.IO.Handle.Text    <entire-module>            229          0    0.0    0.1     0.0    0.1
 CAF           GHC.Show              <entire-module>            214          0    0.0    0.4     0.0    0.4
 CAF           GHC.Event.Thread      <entire-module>            193          0    0.0    1.7     0.0    1.7
 CAF           GHC.Event.Poll        <entire-module>            160          0    0.0    0.1     0.0    0.1
 CAF:main1     Main                  <no location info>         286          0    0.0    0.0     0.0    0.0
  main         Main                  app/Main.hs:(12,1)-(14,48) 288          1    0.0    0.0     0.0    0.0
 CAF:main2     Main                  <no location info>         284          0    0.0    0.0     0.0    0.0
  main         Main                  app/Main.hs:(12,1)-(14,48) 293          0    0.0    0.0     0.0    0.0
   in_range    Main                  app/Main.hs:14:32-48       294          1    0.0    0.0     0.0    0.0
    inr        Main                  app/Main.hs:(20,1)-(21,29) 295          1    0.0    0.0     0.0    0.0
     inr.m     Main                  app/Main.hs:20:13-39       296          1    0.0    0.0     0.0    0.0
 CAF:main4     Main                  <no location info>         285          0    0.0    0.0     0.0    0.0
  main         Main                  app/Main.hs:(12,1)-(14,48) 290          0    0.0    0.0     0.0    0.0
   larger_than Main                  app/Main.hs:13:36-48       291          1    0.0    0.0     0.0    0.0
    lth        Main                  app/Main.hs:17:1-39        292          1    0.0    0.0     0.0    0.0
 main          Main                  app/Main.hs:(12,1)-(14,48) 289          0    0.0   15.8     0.0   15.8

還不知道怎讓才能對enumFromTo生效:(

怣人 回答

你這個是跑到最后一頁,沒有下一頁的鏈接所以提取不出來了吧。。。

喵小咪 回答

Python 的網(wǎng)頁解析一般有以下方法:
1.字符串方法
2.正則表達(dá)式
3.html/xml文本解析庫的調(diào)用(如著名的BeautifulSoup庫)
對于你所給的例子, 假設(shè):

>>> s = '<tr><td><b><a href=".././statistics/power" title="Exponent of the power-law degree distibution">Power law exponent (estimated) with d<sub>min</sub></a></b></td><td>2.1610(d<sub>min</sub> = 2) </td></tr>'

由于文本特征非常明顯, 可以這樣處理:
1.字符串處理方法:

>>> s.split('<td>')[-1].split('(d')[0]
'2.1610'

2.re:

>>> import re
>>> pattern = re.compile('</b></td><td>(.*)\(d<sub>')
>>> pattern.findall(s)
['2.1610']

3.BeautifulSoup:

>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(s, 'html.parser')
>>> soup.find_all('td')[1].contents[0][:-2]
'2.1610'

以上方法均是根據(jù)給定的例子臨時設(shè)計的.

茍活 回答

已找到解決辦法。網(wǎng)頁中有段js是生成token的.

雨萌萌 回答

徑向漸變 定義若干顏色和透明,即形成若干同心圓。無需偽元素

櫻花霓 回答

把<p>里面的內(nèi)容整個提取出string來后用re提取。

r'\<br\>([\w\/]+)$'

clipboard.png

浪婳 回答

當(dāng)然可以。 /\/start[^\/]+type\s*0[^\/]+\/end/g

蟲児飛 回答

java.lang.NullPointerException
應(yīng)該是空指針異常引發(fā)的socke錯誤,檢查賦值操作為NULL的情況

你的瞳 回答

先把你的那個counts轉(zhuǎn)換成字典,然后利用setdefault這個方法。

a_dict = {
    "包" : 3,
    "李" : 3,
    "王" : 2,
    "張" : 2,
    "曹" : 2,
}

result = {}
for k, v in a_dict.items():
    result.setdefault(v, []).append(k)

print(result)

>>> {3: ['包', '李'], 2: ['王', '張', '曹']}
命于你 回答

建議你 看下 Rstan 關(guān)于 Garch 的例子,可以直接復(fù)用

https://github.com/stan-dev/e...

挽青絲 回答

按你的方式改變原數(shù)組

result.forEach(function (v) {
    v.cfr_date.forEach(function (v2, i) {
        if (i==v.cfr_date.length-1) {
            v.cfr_date = v2;
        } else {
            var { ...c } = v;
            c.cfr_date = v2;
            result.push(c)
        }
    })
})

新數(shù)組

var new_result = result.reduce((arr, v) =>
    v.cfr_date.reduce(function (arr2, v2) {
        var { ...c } = v;
        c.cfr_date = v2;
        arr2.push(c)
        return arr2;
    }, arr)
, [])
笑浮塵 回答

一樓的finditer方法是一個非常好的方法,它會返回一個迭代器,而不是返回所有的匹配數(shù)據(jù),這樣的好處一個是節(jié)省內(nèi)存,另一個是能逐個輸出,樓主可以參考,謝謝

笨尐豬 回答

簡單循環(huán)

最簡單的方式就是循環(huán)拆分一下唄。先上最簡單方法:

import pandas as pd
df = pd.DataFrame({'A':['1','2','3'],'B':['1','2,3','4,5,6'],'C':['3','3','3']})
result = pd.DataFrame(columns=['A','B','C'])
print(df,'\n')
for i in df.itertuples():
    for j in i[2].split(','):
        result = result.append({'A':i[1],'B':j,'C':i[3]},ignore_index=True)        
print(result)

輸出:

   A      B  C
0  1      1  3
1  2    2,3  3
2  3  4,5,6  3 

   A  B  C
0  1  1  3
1  2  2  3
2  2  3  3
3  3  4  3
4  3  5  3
5  3  6  3

更高效的方法

采用expand直接進(jìn)行擴(kuò)展

df = pd.DataFrame({'A':['1','2','3'],'B':['1','2,3','4,5,6'],'C':['3','3','3']})
df = (df.set_index(['A','C'])['B']
       .str.split(',', expand=True)
       .stack()
       .reset_index(level=2, drop=True)
       .reset_index(name='B'))
print(df)