<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Data Cleaning
Set up
Imports
Step3:  Parse Raw Data
Step4:  Import into Pandas
Step5:  Technically Correct Data
The data is set to be technically correct if it
Step6:  Data Description
<ASSISTANT_TASK:>
Python Code:
import itertools
import pandas as pd
from scripts.preprocess.parse_json import parse_dir
Explanation: Data Cleaning
Set up
Imports
End of explanation
def parse_station(element):
    Parses a JSON bicycle station object to a dictionary
    obj = {
        'Id': element['id'],
        'Name': element['commonName'],
        'Latitude': element['lat'],
        'Longitude': element['lon'],
        'PlaceType': element['placeType']
    }
    for p in element['additionalProperties']:
        obj[p['key']] = p['value']
        if 'timestamp' not in obj:
            obj['Timestamp'] = p['modified']
        elif obj['Timestamp'] != p['modified']:
            raise ValueError('The properties\' timestamps for station %s do not match: %s != %s' % (
            obj['id'], obj['Timestamp'], p['modified']))
    return obj
def parse_cycles(json_obj):
    Parses TfL's BikePoint JSON response
    return [parse_station(element) for element in json_obj]
records = parse_dir('/home/jfconavarrete/Documents/Work/Dissertation/spts-uoe/data/dev', parse_cycles)
Explanation: Parse Raw Data
End of explanation
dataset = pd.DataFrame(list(itertools.chain.from_iterable(records)))
dataset.shape
Explanation: Import into Pandas
End of explanation
# convert columns to their appropriate datatypes
dataset['InstallDate'] = pd.to_numeric(dataset['InstallDate'], errors='raise')
dataset['Installed'] = dataset['Installed'].astype('bool_')
dataset['Temporary'] = dataset['Temporary'].astype('bool_')
dataset['Locked'] = dataset['Locked'].astype('bool_')
dataset['NbBikes'] = dataset['NbBikes'].astype('uint16')
dataset['NbDocks'] = dataset['NbDocks'].astype('uint16')
dataset['NbEmptyDocks'] = dataset['NbEmptyDocks'].astype('uint16')
# convert string timestamp to datetime
dataset['Timestamp'] =  pd.to_datetime(dataset['Timestamp'], format='%Y-%m-%dT%H:%M:%S.%f')
dataset['InstallDate'] = pd.to_datetime(dataset['InstallDate'], unit='ms')
Explanation: Technically Correct Data
The data is set to be technically correct if it:
can be directly recognized as belonging to a certain variable
is stored in a data type that represents the value domain of the real-world variable.
Convert to Appropriate DataTypes
End of explanation
dataset.info(memory_usage='deep')
dataset.head()
Explanation: Data Description
End of explanation
<END_TASK>