Python code for data management