Posts

Showing posts from July, 2018

pandas dataframe add missing date from range in a multi-dimensional structure with duplicate index

This solution demonstrates how to fill in the missing dates in a given range in a multi-index pandas dataframe. The complexity is added by the presence of duplicate dates in the given data, where the date is considered as an index. In case you try to reindex a data frame with duplicate indexes, you will get the following error. ValueError : cannot reindex from a duplicate axis To resolve this situation and to achieve the end goal of refitting dataset with missing indexes, following pseudo code can be used. Read multidimensional data into pandas dataframe (dataset), with date column as an index (only one index). Transform dataframe index created above into datetime index type Create a new dataframe (d) with the required date range, and value of other records as null Append 'd' into 'dataset' Set index of 'dataset' to include more column to create a multi-level index Reindex to 'dataset', and fill the desired value. The example python co

Python - cannot install mysqlclient with pip

I was trying to intsall mysqlclinet to use following python module oin my program   import MySQLdb as db   As usual it will not work as "mysqlclinet" is not installed. So I tried to install it using pip.   sudo pip install mysqlclient   But it failed with following error. building '_mysql' extension i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG _mysql.c:29:20: fatal error: Python.h: No such file or directory compilation terminated. error: command 'i686-linux-gnu-gcc' failed with exit status 1   I was using python version 3.7.0. I tried everything mentioned in various posts online, but nothing worked.   Many posts suggested using follwoing command:   sudo apt-get install python3-d