I am new to python and have been actively learning for a few weeks. I decided to apply some of the this I learned to try and develop a fictional patient logging program.
I have figured out how to capture inputs from the terminal and save them into a CVS file. Now I was trying to figure out a way to append (aka add on to that document)the file without overwriting the data that is already stored on the .csv file. The method I am using via pandas keeps failing. below is my code so far. I hope you can help.
import pandas as pd
import datetime
date = datetime.datetime.utcnow()
test_list = ['Full', 'Spiro/Gas', 'Spiro', 'Spiro + Rev']
while True:
# Caputring the data
first_name = input('First Name: ')
if first_name == 'quit':
exit()
second_name = input('Second Name: ')
hosp_No = input('CaseNote Number: ')
gender = input('Male(M) or Female (F): ')
yob = int(input('YOB: '))
test = input('Whats test?: ')
# Prepping table parameters for Panadas
titled_columns = {"Date": [date],
"First Name": [first_name],
"Second Name": [second_name],
"Casenote NO": [hosp_No],
"Gender": [gender],
"Year of Birth": [yob],
"Test": [test]}
# OUTPUT and Attempted Appending --- Please help
pt_log_data = pd.DataFrame(titled_columns)
new_pt_line = pd.DataFrame.append(titled_columns[0], ignore_index=True)
pt_log_data.to_csv('PFT_Log.csv')
print("Patient Information Saved")