import pandas as pd


def conv(file):
  ff_name = file
  target_file_name = "ta_"+ff_name
  with open(ff_name, 'rb') as source_file:
    with open(target_file_name, 'w+b') as dest_file:
      contents = source_file.read()
      dest_file.write(contents.decode('utf-16').encode('utf-8'))
  # data = "../docs/test3.csv"
  data = target_file_name
  df = pd.read_csv(data, sep="\t", skiprows=2)  # 制表符分隔tab
  # df = pd.read_csv(data, skiprows=2)  # 制表符分隔tab
  return df

conv("test3.csv")
# df = pd.read_csv(data2, sep=",", skiprows=0, keep_default_na=False, na_values='NULL')  # 制表符分隔tab
# filename = "test"
#
# keywords = df.iloc[0]
# keyword1 = df['Keyword']
# # print("keyword: ", keywords)
# # print("keyword: ", keyword1)
# lines = df.shape
# i = 0


# rows = lines[0]
# db = dataset.connect('mysql://root:pAssw0rd@localhost:3306/keyword?charset=utf8mb4')
# table = db[filename]
# # print(table)
# # for i in range(rows):
# #     row1 = df.iloc[i]
# #     k = df['Keyword']
# #     c = df['Currency']
# #     a = df['Avg monthly searches']
# #     # table.insert(dict(Keyword=k, Currency=c, AvgMonthlySearches=a))
# #     print("row: ", row1)
# #     print("k: ", k)
# #     print("c: ", c)
# #
# #     i += 1
# k = df['Keyword']
# print("k: ", k)
# db.close()
