python 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 attribute 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

What is so wrong with extract()?

I find that it is only bad practice in that it can lead to a number of variables which future maintainers (or yourself in a few weeks) have no idea where they’re coming from. Consider this scenario: extract($someArray); // could be $_POST or anything /* snip a dozen or more lines */ echo $someVariable; Where … Read more

Read Content from Files which are inside Zip file

If you’re wondering how to get the file content from each ZipEntry it’s actually quite simple. Here’s a sample code: public static void main(String[] args) throws IOException { ZipFile zipFile = new ZipFile(“C:/test.zip”); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while(entries.hasMoreElements()){ ZipEntry entry = entries.nextElement(); InputStream stream = zipFile.getInputStream(entry); } } Once you have the InputStream … Read more

Create Pandas DataFrame from txt file with specific pattern

You can first read_csv with parameter name for create DataFrame with column Region Name, separator is value which is NOT in values (like ;): df = pd.read_csv(‘filename.txt’, sep=”;”, names=[‘Region Name’]) Then insert new column State with extract rows where text [edit] and replace all values from ( to the end to column Region Name. df.insert(0, … Read more

Extract MSI from EXE

For InstallShield MSI based projects I have found the following to work: setup.exe /s /x /b”C:\FolderInWhichMSIWillBeExtracted” /v”/qn” This command will lead to an extracted MSI in a directory you can freely specify and a silently failed uninstall of the product. The command line basically tells the setup.exe to attempt to uninstall the product (/x) and … Read more