seriouspark commited on
Commit
b1edd84
β€’
1 Parent(s): 7b1cbee

fix dtype transformation

Browse files
Files changed (1) hide show
  1. make_db.py +9 -9
make_db.py CHANGED
@@ -22,10 +22,10 @@ def app():
22
 
23
 
24
  # 각 열에 λŒ€ν•œ 데이터 νƒ€μž… 선택 μ˜΅μ…˜ 제곡
25
- data_types = {'object': 'String (TEXT)',
26
- 'float' : 'Float (REAL)',
27
- 'int' : 'Integer (INT)',
28
- 'datetime': 'Datetime (TEXT)',
29
  'bool' : 'Bool',
30
  }
31
  selected_data_types = {}
@@ -35,6 +35,7 @@ def app():
35
  format_func = lambda x : data_types[x],
36
  key = column)
37
  selected_data_types[column] = data_type
 
38
  # μ›λž˜ int / float 것듀 μ€‘μ—μ„œ object 둜 λ³€ν™˜ν•΄μ•Ό ν•  것듀은 object 둜 λ°”κΎΈμ–΄μ£ΌκΈ°
39
  if st.button('데이터 λ³€ν™˜ν•˜κ³  μ €μž₯ν•˜κΈ°'):
40
  for column, data_type in selected_data_types.items():
@@ -55,10 +56,8 @@ def app():
55
  elif data_type == 'bool':
56
  df[column] = df[column].astype(bool)
57
  elif data_type == 'object':
58
- if df[column].dtypes == float or df[column].dtypes == int:
59
- df[column] = df[column].astype(str).str.replace('.0','')
60
- else:
61
- df[column] = df[column]
62
 
63
  next = True
64
 
@@ -70,11 +69,12 @@ def app():
70
 
71
  # λ°μ΄ν„°ν”„λ ˆμž„μ„ SQLν…Œμ΄λΈ”λ‘œ λ³€ν™˜
72
 
73
- df.to_sql(f'{file_name}', conn, dtype = selected_data_types, if_exists = 'replace', index = False)
74
 
75
  st.success(f'νŒŒμΌμ€ μ„±κ³΅μ μœΌλ‘œ λ°μ΄ν„°λ² μ΄μŠ€λ‘œ μ €μž₯λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ°μ΄ν„°λ² μ΄μŠ€λͺ… [{file_name}]')
76
 
77
  # μ—°κ²° μ’…λ£Œ
 
78
  conn.close()
79
 
80
 
 
22
 
23
 
24
  # 각 열에 λŒ€ν•œ 데이터 νƒ€μž… 선택 μ˜΅μ…˜ 제곡
25
+ data_types = {'object': 'String',
26
+ 'float' : 'Float',
27
+ 'int' : 'Integer',
28
+ 'datetime': 'Datetime',
29
  'bool' : 'Bool',
30
  }
31
  selected_data_types = {}
 
35
  format_func = lambda x : data_types[x],
36
  key = column)
37
  selected_data_types[column] = data_type
38
+ print(selected_data_types)
39
  # μ›λž˜ int / float 것듀 μ€‘μ—μ„œ object 둜 λ³€ν™˜ν•΄μ•Ό ν•  것듀은 object 둜 λ°”κΎΈμ–΄μ£ΌκΈ°
40
  if st.button('데이터 λ³€ν™˜ν•˜κ³  μ €μž₯ν•˜κΈ°'):
41
  for column, data_type in selected_data_types.items():
 
56
  elif data_type == 'bool':
57
  df[column] = df[column].astype(bool)
58
  elif data_type == 'object':
59
+ df[column] = df[column].astype(str).str.replace('.0','')
60
+
 
 
61
 
62
  next = True
63
 
 
69
 
70
  # λ°μ΄ν„°ν”„λ ˆμž„μ„ SQLν…Œμ΄λΈ”λ‘œ λ³€ν™˜
71
 
72
+ df.to_sql(f'{file_name}', conn, if_exists = 'replace', index = False)
73
 
74
  st.success(f'νŒŒμΌμ€ μ„±κ³΅μ μœΌλ‘œ λ°μ΄ν„°λ² μ΄μŠ€λ‘œ μ €μž₯λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ°μ΄ν„°λ² μ΄μŠ€λͺ… [{file_name}]')
75
 
76
  # μ—°κ²° μ’…λ£Œ
77
+ conn
78
  conn.close()
79
 
80