2017-08-23 25 views
0

私は比較的新しいpythonです。私は数字とテキストのデータ列を持っています。結果はシリーズパンダである必要はありません文字列ベクトルから数字のベクトルを抽出する

result=pd.Series([[1200,1050],[],[2200,10570]]) 

import pandas as pd 
mycolumn=pd.Series(["I w0n 1200$ in poker and got 1050$ on my b111rthday", 
         "another month was b4d, I only earned 150$", 
         "d4d gave 2200, lost 0420$ in poker in 10570 Berlin"]) 

私はそのようなことを1000年の上のすべての値を取り出したいです。他のフォーマットでは、後で空のセルやスムースを使用して残りのデータをサブセット化することができます。

答えて

3

4は、少なくとも4つの位置を意味(\d{4,})で使用str.findall、すなわち> 1000年

In [876]: mycolumn.str.findall('(\d{4,})') 
Out[876]: 
0   [1200, 1050] 
1      [] 
2 [2200, 0420, 56454] 
dtype: object 

そして、pointedとして、あなたは0使用して

In [877]: mycolumn.str.findall('([1-9]\d{3,})') 
Out[877]: 
0  [1200, 1050] 
1    [] 
2 [2200, 56454] 
dtype: object 

詳細を開始する番号をしたくない場合は

In [878]: mycolumn 
Out[878]: 
0 I w0n 1200$ in poker and got 1050$ on my b111r... 
1   another month was b4d, I only earned 150$ 
2  d4d gave 2200, lost 0420$ with 56454 in poker 
dtype: object 
+0

'\ d {4、 } 'はい。 –

+0

これは期待値ではないかもしれませんが、これは例えば '0999'にも一致します。 –

+0

あなたは正規表現を保持し、 '[1-9] \ d {3、}'を実行することができます。 –

関連する問題