मेरे पास स्ट्रिंग्स की नेस्टेड सूची है जिसे मैं उन्हें तारीख निकालना चाहता हूं। दिनांक स्वरूप है:पांडा एक्स्ट्रेक्टॉल() रेगेक्स दिए गए सभी मामलों को निकालने नहीं कर रहा है?
import pandas as pd
df = pd.DataFrame({'blobs':['6-Feb- 1 4 Facebook’s virtual-reality division created a 3-EBÚ7 11 network of 500 free demo stations in Best Buy stores to give people a taste of VR using the Oculus Rift 90 GT 48 headset. But according to a Wednesday report from Business Insider, about 200 of the demo stations will close after low interest from consumers. 17-Feb-2014',
'I think in a store environment getting people to sit down and go through that experience of getting a headset on and getting set up is quite a difficult thing to achieve,” said Geoff Blaber, a CCS Insight analyst. 29—Oct-2012 Blaber 32 FAX 2978 expects that it will get easier when companies can convince 18-Oct-12 credit cards. '
]})
df
फिर
:
df['blobs'].str.extractall(r'\d{2}(—|-)(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2,4}')
r'\d{2}(—|-)(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2,4}'
तो मैं यह इस प्रकार का परीक्षण किया:
Two numbers (from
01
to12
) hyphen tree letters (a valid month) hyphen two numbers, for example:08-Jan—07
or03-Oct—01
मैं निम्नलिखित regex का उपयोग करने की कोशिश की फिर भी, वे काम नहीं कर रहे हैं। पिछले regex मुझे कुछ भी नहीं देता है (यानी सिर्फ -
hypens):
Col
0 NaN
1 -
2 -
3 NaN
4 NaN
5 -
...
n -
कैसे मैं उन्हें क्रम में ठीक कर सकते हैं ?:
Col
0 6-Feb-14, 17-Feb-2014
1 29—Oct-2012, 18-Oct-12
अद्यतन प्राप्त करने के लिए
मैंने यह भी करने की कोशिश की:
import re
df['col'] = df.blobs.apply(lambda x: re.findall('\d{2}(—|-)(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2,4}',x))
s = df.apply(lambda x: pd.Series(x['col']),axis=1).stack().reset_index(level=1, drop=True)
s.name = "col"
df = df.drop('col')
df
फिर भी मैं भी मिल गया:
ValueError Traceback (most recent call last)
<ipython-input-4-5e9a34bd159f> in <module>()
3 s = df.apply(lambda x: pd.Series(x['col']),axis=1).stack().reset_index(level=1, drop=True)
4 s.name = "col"
----> 5 df = df.drop('col')
6 df
/usr/local/lib/python3.5/site-packages/pandas/core/generic.py in drop(self, labels, axis, level, inplace, errors)
1905 new_axis = axis.drop(labels, level=level, errors=errors)
1906 else:
-> 1907 new_axis = axis.drop(labels, errors=errors)
1908 dropped = self.reindex(**{axis_name: new_axis})
1909 try:
/usr/local/lib/python3.5/site-packages/pandas/indexes/base.py in drop(self, labels, errors)
3260 if errors != 'ignore':
3261 raise ValueError('labels %s not contained in axis' %
-> 3262 labels[mask])
3263 indexer = indexer[~mask]
3264 return self.delete(indexer)
ValueError: labels ['col'] not contained in axis
':' गलत वर्तनी, सही है (?)? 'आर "\ b \ d {2} - (?: जनवरी | फरवरी | मार्च | अप्रैल | मई | जून | जुलाई | अगस्त | सितंबर | अक्टूबर | नवंबर | दिसंबर) - \ d {2} \ b" '। यदि एन-या-डैश हो सकते हैं, तो '---- '' --- ---' के साथ बदलें। –
एक नज़र में, आपके regexes हाइफ़न से मेल नहीं खाते हैं। – Kevin
यदि आप '6-Feb' स्वीकार करना चाहते हैं, तो आपको दो की बजाय _one_ संख्या अपफ्रंट की अनुमति देनी होगी। जैसे '\ d {1,2}' – khelwood