text: import os
  import pandas as pd
  import pymysql
  
  
  conn = pymysql.connect(
      user='root',
      passwd='Elql27!^',
      host='165.132.105.40',
      db='projectBigdata',
      charset='utf8'
  )
  
  
  pd.set_option('display.max_row', 20000)
  pd.set_option('display.max_columns', 10000)
  
  # minLatitude = 37.508192
  # maxLatitude = 37.509788
  # minLongitude = 127.061661
  # maxLongitude = 127.064449
  minLatitude = 35.427693
  maxLatitude = 38.527869
  minLongitude = 121.040601
  maxLongitude = 129.040758
  grid_cnt = 10
  
  gap_Latitude = (maxLatitude - minLatitude) / grid_cnt
  gap_Longitude = (maxLongitude - minLongitude) / grid_cnt
  
  list_lati = []
  list_longi = []
  
  for i in range(grid_cnt):
      list_lati.append(minLatitude + (gap_Latitude * i))
      list_longi.append(minLongitude + (gap_Longitude * i))
  
  # print("list lati : ", list_lati)
  # print("list longi : ", list_longi)
  
  folder_name = '../3_location/20190819_after'
  
  # file = "../3_location/1126_test/total.txt"
  # if os.path.isfile(file):
  #     os.remove(file)
  
  # file = "../3_location/1126_test/total_sort.txt"
  # if os.path.isfile(file):
  #     os.remove(file)
  
  df_total = pd.DataFrame(
      columns=['timestamp', 'date', 'car_id', 'lat', 'long', 'grid'])
  
  for root, dirs, files in os.walk(folder_name):
      for fname in files:
          full_fname = os.path.join(root, fname)
          file = open(full_fname, 'r', encoding='utf8')
          s = file.read()
          data = s.split('\n')
          for i in range(len(data)):
              data_2 = data[i].split('\t')
              if data_2[0] == '':
                  continue
              else:
                  lati = float(data_2[3])
                  longi = float(data_2[4])
                  for j in range(grid_cnt):
                      if j == (grid_cnt - 1):
                          grid_lati = grid_cnt - 1
                      elif lati >= list_lati[j] and lati < list_lati[j+1]:
                          grid_lati = j
                          break
  
                  for j in range(grid_cnt):
                      if j == (grid_cnt - 1):
                          grid_longi = grid_cnt - 1
                      elif longi >= list_longi[j] and longi < list_longi[j+1]:
                          grid_longi = j
                          break
  
                  grid_add = str(grid_lati) + str(grid_longi)
                  df_total.loc[len(df_total)] = [
                      data_2[0], data_2[1], data_2[2], data_2[3], data_2[4], grid_add]
          file.close()
  df_total = df_total.sort_values(by=['car_id', 'date'], axis=0).reset_index(
      drop=True)  # car_id, date를 기준으로 오름차순 정렬 및 index reset
  # print("to : ", df_total)
  html = df_total.to_html()
  print(df_total)
  print(html)
  
  df_trans = pd.DataFrame(columns=['car_id', 'grid_trans'])
  
  for i in range(len(df_total)):
      if i == 0:
          target_car_id = df_total.car_id[i]
          grid_list = []
          grid_list.append(df_total.grid[i])
      else:
          # print(i, ' : ', df_total.car_id[i], target_car_id)
          if df_total.car_id[i] == target_car_id:
              # print(i, "target : ", target_car_id, "same")
              temp_grid = df_total.grid[i]
              if temp_grid not in grid_list and len(grid_list) <= 3:
                  grid_list.append(temp_grid)
          else:
              if i == (len(df_total) - 1):  # 마지막인데 다를 경우
                  # print(i, "target : ", target_car_id, "not same final")
                  df_trans.loc[len(df_trans)] = [target_car_id,
                                                 ','.join(grid_list)]  # save previous data
  
                  grid_list = []
                  grid_list.append(df_total.grid[i])
                  df_trans.loc[len(df_trans)] = [df_total.car_id[i], ','.join(
                      grid_list)]  # save previous data
  
              else:
                  # print(i, "target : ", target_car_id, "not same")
                  df_trans.loc[len(df_trans)] = [target_car_id,
                                                 ','.join(grid_list)]  # save previous data
                  grid_list = []  # grid list initialize
                  target_car_id = df_total.car_id[i]  # set target id
                  grid_list.append(df_total.grid[i])
  
  print("res : ", df_trans)
  
  curs = conn.cursor()
  sql = "INSERT INTO 0_data_input (tid, uid, items) VALUES (%s, %s, %s)"
  
  # for i in range(len(df_trans)) :
  for i in range(len(df_trans)):
      items = df_trans.grid_trans[i]
      curs.execute(sql, (i, i, items))
  
  conn.commit()
  