{"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 numpy as np\nimport pandas as pd ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-11T11:50:15.394096Z","iopub.execute_input":"2021-12-11T11:50:15.394566Z","iopub.status.idle":"2021-12-11T11:50:15.398799Z","shell.execute_reply.started":"2021-12-11T11:50:15.394519Z","shell.execute_reply":"2021-12-11T11:50:15.397917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"TRAIN_PATH = \"../input/landmark-recognition-2021/train.csv\"\nOUTPUT_NUM = 5","metadata":{"execution":{"iopub.status.busy":"2021-12-11T11:50:15.400749Z","iopub.execute_input":"2021-12-11T11:50:15.401550Z","iopub.status.idle":"2021-12-11T11:50:15.416510Z","shell.execute_reply.started":"2021-12-11T11:50:15.401501Z","shell.execute_reply":"2021-12-11T11:50:15.415678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(TRAIN_PATH)\ntrain = train[:OUTPUT_NUM]\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-11T11:50:15.417883Z","iopub.execute_input":"2021-12-11T11:50:15.418220Z","iopub.status.idle":"2021-12-11T11:50:16.672845Z","shell.execute_reply.started":"2021-12-11T11:50:15.418172Z","shell.execute_reply":"2021-12-11T11:50:16.671749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2021-12-11T11:50:16.674495Z","iopub.execute_input":"2021-12-11T11:50:16.674757Z","iopub.status.idle":"2021-12-11T11:50:16.683689Z","shell.execute_reply.started":"2021-12-11T11:50:16.674726Z","shell.execute_reply":"2021-12-11T11:50:16.683102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1. DataFrame.values = > row item list data )","metadata":{}},{"cell_type":"code","source":"train.values","metadata":{"execution":{"iopub.status.busy":"2021-12-11T11:50:16.685513Z","iopub.execute_input":"2021-12-11T11:50:16.686243Z","iopub.status.idle":"2021-12-11T11:50:16.700352Z","shell.execute_reply.started":"2021-12-11T11:50:16.686202Z","shell.execute_reply":"2021-12-11T11:50:16.699422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for row in train.values:\n    print(row[0],\" \",row[1])\n    print(\"\")","metadata":{"execution":{"iopub.status.busy":"2021-12-11T11:50:16.702008Z","iopub.execute_input":"2021-12-11T11:50:16.702384Z","iopub.status.idle":"2021-12-11T11:50:16.715426Z","shell.execute_reply.started":"2021-12-11T11:50:16.702347Z","shell.execute_reply":"2021-12-11T11:50:16.714734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 2.DataFrame.iterrows() = >row index ,row data","metadata":{}},{"cell_type":"code","source":"for i,row in train.iterrows():\n    print(i,\" \",row[0])","metadata":{"execution":{"iopub.status.busy":"2021-12-11T11:50:16.716869Z","iopub.execute_input":"2021-12-11T11:50:16.717775Z","iopub.status.idle":"2021-12-11T11:50:16.731090Z","shell.execute_reply.started":"2021-12-11T11:50:16.717729Z","shell.execute_reply":"2021-12-11T11:50:16.730172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 3.DataFrame.items() => column name, column Series","metadata":{}},{"cell_type":"markdown","source":"### Iterate over (column name, Series) pairs.","metadata":{}},{"cell_type":"code","source":"for label, content in train.items():\n    print(\"label=>\",label)\n    print(\"content=>\")\n    print(content)\n    print(\"\")","metadata":{"execution":{"iopub.status.busy":"2021-12-11T12:01:40.412359Z","iopub.execute_input":"2021-12-11T12:01:40.412987Z","iopub.status.idle":"2021-12-11T12:01:40.421377Z","shell.execute_reply.started":"2021-12-11T12:01:40.412927Z","shell.execute_reply":"2021-12-11T12:01:40.420508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 4.DataFrame.iteritems()","metadata":{}},{"cell_type":"markdown","source":"### Iterate over (column name, Series) pairs.","metadata":{}},{"cell_type":"markdown","source":"dict.items() returns a list of 2-tuples ([(key, value), (key, value), ...]), \nwhereas dict.iteritems() is a generator that yields 2-tuples. \n\nThe former takes more space and time initially, \n\nbut accessing each element is fast, whereas the second takes less space \nand time initially, but a bit more time in generating each element.","metadata":{}},{"cell_type":"code","source":"for label,item in train.iteritems():\n    print(label)\n    print(item)\n    print(\"\")\n    ","metadata":{"execution":{"iopub.status.busy":"2021-12-11T12:03:00.293932Z","iopub.execute_input":"2021-12-11T12:03:00.294224Z","iopub.status.idle":"2021-12-11T12:03:00.301197Z","shell.execute_reply.started":"2021-12-11T12:03:00.294194Z","shell.execute_reply":"2021-12-11T12:03:00.300338Z"},"trusted":true},"execution_count":null,"outputs":[]}]}