Spaces:
Sleeping
Sleeping
seriouspark
commited on
Commit
β’
b1edd84
1
Parent(s):
7b1cbee
fix dtype transformation
Browse files- make_db.py +9 -9
make_db.py
CHANGED
@@ -22,10 +22,10 @@ def app():
|
|
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,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 |
-
|
59 |
-
|
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,
|
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 |
|