I have been getting a weird error that I'm not able to explain with any online source. I've been working on a school project.I tried assigning some input values into a list. The list was going to be used to define a new row into the existing dataframe, during which I encountered the error:
from datetime import datetime
from datetime import date
import os
import csv
import pandas as pd
import matplotlib.pyplot as pl
df = pd.DataFrame(columns=["First_Name","Last_Name","Aadhar_No.","city","DOB","Age","DOA","DOR",'sentence_indays',"sentence_inyears","crime"])
if os.path.exists("Criminaldb.csv"):
print("Welcome back!")
else:
print("Kindly please restart the program after this process is completed.")
with open("Criminaldb.csv",'w') as file:
pass
df.to_csv("Criminaldb.csv",mode='a')
exit()
print('''Welcome to Criminal prison DB record app!
What do you wish to do today?
1) Add new entry
2) Update previous record
3) Find and sort old records
4) Delete a record
5) Exit the program''')
choice = int(input())
if choice == 1:
print("Please fill out the asked details in the suggested formats only.")
total_entries = int(input("How many entries are to be done?(Numeric values only)"))
for i in range(1,total_entries+1):
print("Entry no. ",i )
first_name=input("First name ")
last_name=input("Last name ")
Aadhar = input("Aadhar no. ")
city = input("Enter the city name(First letter capital)")
cmnl_ID = input("Crimimal ID assigned ")
DOB = input("Date of Birth(YYYYMMDD format) ")
year,month,day= DOB[:4],DOB[4:6],DOB[6:9]
if month[0] == '0':
month = month[1]
if day[0] == '0':
day = day[1]
else:
pass
ageindays = date(int(year),int(month),int(day))
age = date.today() - ageindays
age = int(age.days/365)
DOA = input("Date of admission(Same format as before)")
if DOA == '':
DOA = date.today()
else:
yr_adm, mon_adm, day_adm = DOA[:4],DOA[4:6],DOA[6:9]
if mon_adm[0] == '0':
mon_adm = mon_adm[1]
if yr_adm[0] == '0':
yr_adm = yr_adm[1]
else:
pass
DOA = date(int(yr_adm),int(mon_adm),int(day_adm))
DOR = input("Date of Release(Same format as before,leave blank for life imprisonment) ")
if DOR == '':
DOR = 'N/A'
else:
yr_rel,mon_rel,day_rel = DOR[:4],DOR[4:6],DOR[6:9]
if mon_rel[0] == '0':
mon_rel = mon_rel[1]
if day_rel[0] == '0':
day_rel = day_rel[1]
DOR = date(int(yr_rel),int(mon_rel),int(day_rel))
total_sentence = DOR-DOA
sentence_indays= total_sentence.days
sentence_inyears= round(float(total_sentence.days)/365, 1)
crime = input("Crime done by the criminal ")
entrylist = {'First_Name':first_name,'Last_Name':last_name,'Aadhar_No':Aadhar,'city':city,'DOB':DOB,'Age':age,'DOA':DOA,'DOR':DOR,'sentence_indays':sentence_indays,'sentence_inyears':sentence_inyears,'crime':crime}
df.at[str(cmnl_ID),:] = entrylist
if choice == '2':
print("Please Remember to enter data in suggested formats only!")
findCrim = input("Please give the Criminal ID of the criminal whose query you need to make changes to: ")
with open('Criminaldb.csv','r') as finder:
f2 = csv.reader(finder)
for i in f2:
if i[4] == findCrim:
print("Entry found!")
print('Current details:')
for j in range(11):
print(fields[j],": ",i[j])
print("Please proceed ")
else:
print("No entry with Criminal ID ",findCrim," found!")
continue
if choice== '5':
print("Exiting..")
exit()
When using the "Add new entry" option of this code and providing it with the required inputs, it gives the following error:
Can anyone please help me out with this? Any relevant responses would be greatly appreciated.
Environment info: Main env: Termux
Termux Variables:
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP__AM_SOCKET_SERVER_ENABLED=true TERMUX_APP__APK_PATH=/data/app/~~w5pcxTLDl6SFk1Zoh9vmlQ==/com.termux-3prOjAH5DyBS7ay61hWIkA==/base.apk
TERMUX_APP__APK_RELEASE=GITHUB
TERMUX_APP__FILES_DIR=/data/user/0/com.termux/files
TERMUX_APP__IS_DEBUGGABLE_BUILD=true TERMUX_APP__IS_INSTALLED_ON_EXTERNAL_STORAGE=false
TERMUX_APP__PACKAGE_MANAGER=apt
TERMUX_APP__PACKAGE_NAME=com.termux TERMUX_APP__PACKAGE_VARIANT=apt-android-5
TERMUX_APP__PID=15476
TERMUX_APP__SE_FILE_CONTEXT=u:object_r:app_data_file:s0:c87,c257,c512,c768
TERMUX_APP__SE_INFO=default:targetSdkVersion=28:complete
TERMUX_APP__SE_PROCESS_CONTEXT=u:r:untrusted_app_27:s0:c87,c257,c512,c768
TERMUX_APP__TARGET_SDK=28
TERMUX_APP__UID=10343
TERMUX_APP__USER_ID=0 TERMUX_APP__VERSION_CODE=118
TERMUX_APP__VERSION_NAME=0.118.0+a523911
TERMUX_MAIN_PACKAGE_FORMAT=debian TERMUX_VERSION=0.118.0+a523911
Packages CPU architecture: aarch64
Subscribed repositories:
deb https://mirrors.cbrx.io/apt/termux/termux-main stable main
# sources.list.d/ivam3-termux-packages.list deb [trusted=yes arch=all] https://ivam3.github.io/termux-packages stable extras
# root-repo (sources.list.d/root.list)
deb https://mirrors.cbrx.io/apt/termux/termux-root root stable
# x11-repo (sources.list.d/x11.list)
deb https://mirrors.cbrx.io/apt/termux/termux-x11 x11 main
# sources.list.d/termux-desktop-xfce.list
deb [trusted=yes arch=all] https://Yisus7u7.github.io/termux-desktop-xfce/packages desktop-xfce extras
# tur-repo (sources.list.d/tur.list) deb https://tur.kcubeterm.com tur-packages tur tur-on-device tur-continuous
Updatable packages:
beef/stable 0.5.4.0-soa all [upgradable from: 0.5.4.0-dev]
i-haklab/stable 3.7.0 all [upgradable from: 3.6.7] nodejs/stable 20.2.0 aarch64 [upgradable from: 19.6.1]
termux-tools version: 1.38.3 - Android version: 13
Kernel build information: Linux localhost 4.14.186-g584a03637-dirty #1 SMP PREEMPT Tue May 16 15:17:01 CST 2023 aarch64 Android
Device manufacturer: vivo
Device model: V2117
LD Variables:
LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
