<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 This is the companion jupyter notebook to 'ageDataOver65.py'.
Purpose
Step1:  <font color = 'blue'> get a list of the column names </font>
Step2:  <font color='blue'> function
Step3:  codingDF is intended to be used as a lookup table for recoding. <br />
codingDF contains 2 columns
Step4:  The 2 cells below are my attempts to recode the ageData column names. <br />
Some things to deal with
<ASSISTANT_TASK:>
Python Code:
import pandas
import numpy
import os
import ijson
path = os.chdir('/Users/superuser/Documents/projects/SDRegionalDataLib/age friendly community/acs2015_1yr_B01001/')
ageData = pandas.read_csv('acs2015_1yr_B01001.csv');
ageData.head()
Explanation: This is the companion jupyter notebook to 'ageDataOver65.py'.
Purpose: open a CSV file from https://censusreporter.org/ and recode it with the corresponding JSON metadata file.
Written by CC on 20161228
End of explanation
colNames = list(ageData.columns.values)
#show the first ten coded column names
colNames[0:9]
#open the json file
jsonFile = 'metadata.json';
with open(jsonFile, 'r') as f:
    objects = ijson.items(f, 'tables.B01001.columns')
    columnAttr = list(objects)
#show the values of columnAttr
columnAttr[:]
Explanation: <font color = 'blue'> get a list of the column names </font>
End of explanation
def getRecodingKeys(element):
    if ('Error' not in element) and ('name' != element) and ('geoid' != element):
        return element
    return False
#filter out the original column names that don't require recoding
codingDF = pandas.DataFrame({'origColNames': list(filter(getRecodingKeys, colNames))})
#add a new column to codingDF that contains the recoded ageDF column names
codingDF['recodeColName'] = ''
Explanation: <font color='blue'> function: getRecodingKeys filters out column names that don't need to be recoded </font>
<font color = 'blue'> codingDF is a lookup table that can be use to recode the column names of ageData </font>
End of explanation
#append the recodedColNames to codingDF.recodeColName
for idx, origColName in enumerate(codingDF.origColNames):
    codingDF.recodeColName[idx] = columnAttr[0][origColName]['name']
codingDF.head()
Explanation: codingDF is intended to be used as a lookup table for recoding. <br />
codingDF contains 2 columns: <br />
origColNames: contain the original coded column name in the ageData dataframe <br />
recodeColName: contains the actual column names that are a lot more descriptive than the coded column names in the ageData dataframe
End of explanation
#recode ageData with the actual column names
for idx, col in enumerate(ageData.columns):
    if  codingDF.origColNames.str.contains(col): #codingDF.origColNames.str.contains(ageData.columns[idx]):
        colMatchIDX = codingDF.origColNames.get_loc(col)
        if ageData.columns[idx].str.contains('Error'):
            tempColName = codingDF.recodeColName[colMatchIDX] + '_Error'
            ageData.columns[idx] = tempColName
        else:
            tempColName = codingDF.recodeColName[colMatchIDX]
#recode ageData with the actual column names
for idx, col in enumerate(ageData.columns):
    if  codingDF.origColNames.str.contains(col): #codingDF.origColNames.str.contains(ageData.columns[idx]):
        colMatchIDX = codingDF.origColNames.get_loc(col)
        if ageData.columns[idx].str.contains('Error'):
            tempColName = codingDF.recodeColName[colMatchIDX] + '_Error'
            ageData.rename(columns={col:tempColName}, inplace=True)
        else:
            tempColName = codingDF.recodeColName[colMatchIDX]
            print(tempColName)
            ageData.rename(columns={col:tempColName}, inplace=True)
Explanation: The 2 cells below are my attempts to recode the ageData column names. <br />
Some things to deal with: <br />
1) Each coded column name in the ageData dataframe 'B01001xxx' for instance has a corresponding column cotaining the error of each measurement with a column name 'B01001xxx, Error'.
2) Finding the index values of python/pandas dataframe where the rows are equal to a certain value.  In CRAN-R you could execute the following code: 'index = which(dataFrame$column=='B01001xxx')'.  A python/pandas equivalent would be great if there is one.
End of explanation
<END_TASK>