{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport ast","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-23T12:53:13.211616Z","iopub.execute_input":"2021-11-23T12:53:13.212752Z","iopub.status.idle":"2021-11-23T12:53:13.218130Z","shell.execute_reply.started":"2021-11-23T12:53:13.212693Z","shell.execute_reply":"2021-11-23T12:53:13.216806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# String => Expression","metadata":{}},{"cell_type":"code","source":"expressionString1 = \"{'a': 1, 'b': 2, 'c': 3}\"\nprint(ast.literal_eval(expressionString1))\n\nexpressionString2 = \"[1, 2, 3, 4, 5]\"\nprint(ast.literal_eval(expressionString2))\n\nexpressionString3 = \"[(1,2),(3,4),(5,6)]\"\nprint(ast.literal_eval(expressionString3))\n\nexpressionString4 = \"[{'x': 559, 'y': 213, 'width': 50, 'height': 32}]\"\nprint( ast.literal_eval(expressionString4) )\n\nexpressionString5 = \"[{'x': 100, 'y': 100, 'width': 50, 'height': 50},{'x': 200, 'y': 200, 'width': 30, 'height': 30}]\"\nprint( ast.literal_eval(expressionString5) )\n","metadata":{"execution":{"iopub.status.busy":"2021-11-23T12:53:13.220054Z","iopub.execute_input":"2021-11-23T12:53:13.220305Z","iopub.status.idle":"2021-11-23T12:53:13.234603Z","shell.execute_reply.started":"2021-11-23T12:53:13.220276Z","shell.execute_reply":"2021-11-23T12:53:13.232672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# get rows with annotations != []","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv(\"../input/tensorflow-great-barrier-reef/train.csv\")\ntrain = train.loc[train[\"annotations\"] != \"[]\"]\ntrain = train.reset_index(drop = True)\ntrain.head(30)","metadata":{"execution":{"iopub.status.busy":"2021-11-23T12:53:13.235626Z","iopub.execute_input":"2021-11-23T12:53:13.236166Z","iopub.status.idle":"2021-11-23T12:53:13.298645Z","shell.execute_reply.started":"2021-11-23T12:53:13.236111Z","shell.execute_reply":"2021-11-23T12:53:13.297813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"- annotations type is object.\n- it needs to convert expression","metadata":{}},{"cell_type":"code","source":"train.info()","metadata":{"execution":{"iopub.status.busy":"2021-11-23T13:00:13.403410Z","iopub.execute_input":"2021-11-23T13:00:13.403898Z","iopub.status.idle":"2021-11-23T13:00:13.417979Z","shell.execute_reply.started":"2021-11-23T13:00:13.403832Z","shell.execute_reply":"2021-11-23T13:00:13.416941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# type check ","metadata":{}},{"cell_type":"code","source":"a = train.iloc[0][\"annotations\"] \nb = ast.literal_eval(train.iloc[0][\"annotations\"])\nprint(a , type(a), len(a))\nprint(b, type(b),len(b))","metadata":{"execution":{"iopub.status.busy":"2021-11-23T12:53:13.299888Z","iopub.execute_input":"2021-11-23T12:53:13.300240Z","iopub.status.idle":"2021-11-23T12:53:13.307659Z","shell.execute_reply.started":"2021-11-23T12:53:13.300206Z","shell.execute_reply":"2021-11-23T12:53:13.306843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = train.iloc[19][\"annotations\"] \nb = ast.literal_eval(train.iloc[19][\"annotations\"]) \nprint(a , type(a), len(a))\nprint(b, type(b),len(b))","metadata":{"execution":{"iopub.status.busy":"2021-11-23T12:53:13.309573Z","iopub.execute_input":"2021-11-23T12:53:13.309775Z","iopub.status.idle":"2021-11-23T12:53:13.320467Z","shell.execute_reply.started":"2021-11-23T12:53:13.309751Z","shell.execute_reply":"2021-11-23T12:53:13.319842Z"},"trusted":true},"execution_count":null,"outputs":[]}]}