-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_info.py
47 lines (41 loc) · 1.81 KB
/
update_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def app():
import streamlit as st
import pandas as pd
#make a title for your webapp
st.title("Update Information")
st.markdown('**NOTE: ** _You can only update address or mobile number_.')
eid = st.text_input('Enter the Employee ID whose data you want to update')
st.write('Select what you want to update:')
option_1 = st.checkbox('Address')
option_2 = st.checkbox('Mobile Number')
if option_1:
if option_2:
new_mob_num = st.text_input('Enter New Mobile number')
new_address = st.text_input('Enter New Address')
else:
new_mob_num = st.text_input('Enter New Address')
elif option_2:
new_mob_num = st.text_input('Enter New Mobile number')
clickSubmit = st.button('Update')
if clickSubmit == True:
df = pd.read_csv('user.txt')
res = (df[df['Employee_ID'] == int(eid)])
st.markdown('**The Old entry was as follows: **')
st.dataframe(res)
if option_1:
if option_2:
res['Address'] = [new_address]
res['Mobile_Number'] = [str(new_mob_num)]
else:
res['Address'] = [new_address]
elif option_2:
res['Mobile_Number'] = [str(new_mob_num)]
st.markdown('**The Update entry is as follows: **')
st.dataframe(res)
#### This is used to update the original dataframe. Set index sets employee id as the S.NO of the data frame. It makes it easy to update.
df.set_index('Employee_ID', inplace=True)
df.update(res.set_index('Employee_ID'))
### This is used to bring the original index back.
df.reset_index(inplace=True)
#### This is used to save csv as text file.
df.to_csv('user.txt', index=None, sep=',')