pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working

If you’re running a recent-ish version of pandas then you can use the datetime accessor dt to access the datetime components: In [6]: df[‘date’] = pd.to_datetime(df[‘date’]) df[‘year’], df[‘month’] = df[‘date’].dt.year, df[‘date’].dt.month df Out[6]: date Count year month 0 2010-06-30 525 2010 6 1 2010-07-30 136 2010 7 2 2010-08-31 125 2010 8 3 2010-09-30 84 … Read more

How can I extract text from a PDF file in Perl?

These modules you can acheive the extract text from pdf PDF::API2 CAM::PDF CAM::PDF::PageText From CPAN my $pdf = CAM::PDF->new($filename); my $pageone_tree = $pdf->getPageContentTree(1); print CAM::PDF::PageText->render($pageone_tree); This module attempts to extract sequential text from a PDF page. This is not a robust process, as PDF text is graphically laid out in arbitrary order. This module uses … Read more

Regular expressions C# – is it possible to extract matches while matching?

You can use regex groups to accomplish that. For example, this regex: (\d\d\d)-(\d\d\d\d\d\d\d) Let’s match a telephone number with this regex: var regex = new Regex(@”(\d\d\d)-(\d\d\d\d\d\d\d)”); var match = regex.Match(“123-4567890”); if (match.Success) …. If it matches, you will find the first three digits in: match.Groups[1].Value And the second 7 digits in: match.Groups[2].Value P.S. In C#, … Read more

How can I extract the folder path from file path in Python?

You were almost there with your use of the split function. You just needed to join the strings, like follows. >>> import os >>> ‘\\’.join(existGDBPath.split(‘\\’)[0:-1]) ‘T:\\Data\\DBDesign’ Although, I would recommend using the os.path.dirname function to do this, you just need to pass the string, and it’ll do the work for you. Since, you seem to … Read more