r/PythonLearning • u/Sad_Commission1110 • Oct 13 '25
r/PythonLearning • u/Local_End_3175 • Jul 27 '26
why are we putting caesar( Hello, 3) into encrypted_text???
def caesar(text, shift):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_table = str.maketrans(alphabet, shifted_alphabet)
encrypted_text = text.translate(translation_table)
print(encrypted_text)
encrypted_text = caesar('Hello',3)in this code, I do not understand why we are putting caesar into a variable. First of all, wouldn't we have to print the variable and make it actually do something for it to work? Because we have put encrypted_text into a variable and have not done anything. In addition, can't we just write caesar('Hello', 3)?? I am very confused on the reasoning behind putting it into a variable.
r/PythonLearning • u/Alwaysrainyintacoma • May 15 '25
Help Request Looking for feedback on how to clean this up. Pretty new.
Edit:
Made aware the formatting got messed up.
GitHub.com/Always-Rainy/fec
from bs4 import BeautifulSoup as bs import requests from thefuzz import fuzz, process import warnings import pandas as pd import zipfile import os import re import numpy as np import unicodedata from nicknames import NickNamer import win32com.client import time import datetime from datetime import date import glob import openpyxl from openpyxl.utils import get_column_letter from openpyxl.worksheet.table import Table, TableStyleInfo from openpyxl.worksheet.formula import ArrayFormula from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains import xlwings as xw from functools import lru_cache from dotenv import load_dotenv import os from constants import ( fec_url, house_url, senate_url, house_race_url, senate_race_url, not_states, fec_columns, state2abbrev, house_cats, house_rate_cat ) senate_race_url = 'https://www.cookpolitical.com/ratings/senate-race-ratings' load_dotenv('D:\MemberUpdate\passwords.env') BGOV_USERNAME = os.getenv('BGOV_USERNAME') BGOV_PASSWORD = os.getenv('BGOV_PASSWORD')
nn = NickNamer.from_csv('names.csv') warnings.filterwarnings("ignore")
new_names = ['Dist','MOC','Party'] all_rows = [] vacant_seats = [] Com_Names = [] Sub_Names = [] party = ['rep', 'dem']
def column_clean(select_df, column_name, column_form): select_df[column_name] = select_df[column_name].apply(lambda x: re.sub(column_form,"", x))
def name_column_clean(select_df, target_column): column_clean(select_df, target_column, r'[a-zA-Z]{,3}[.]' ) column_clean(select_df, target_column, r'\b[a-zA-Z]{,1}\b') column_clean(select_df, target_column, r'\b[MRDSJmrdsj]{,2}\b') column_clean(select_df, target_column, r'(.)') column_clean(select_df, target_column, r'[0-9]}') column_clean(select_df, target_column, r''.'') column_clean(select_df, target_column, r'\b[I]{,3}\b')
@lru_cache(maxsize=1000) def name_norm(name_check): try: new_name = nn.canonicals_of(name_check).pop() except: new_name = name_check
return new_namedef name_insert_column(select_df): insert_column(select_df, 1, 'First Name') insert_column(select_df, 1, 'Last Name') insert_column(select_df, 1, 'Full Name')
def name_lower_case(select_df): lower_case(select_df, 'Last Name') lower_case(select_df, 'First Name') lower_case(select_df, 'Full Name')
def insert_column(select_df, pos, column_name): select_df[column_name]=select_df.insert(pos,column_name,'')
def lower_case(select_df, column_name): select_df[column_name]=select_df[column_name].str.lower()
def text_replace (select_df, column_name, original, new): select_df[column_name]=select_df[column_name].str.replace(original, new)
def text_norm (select_df): cols = select_df.select_dtypes(include=[object]).columns select_df[cols] = select_df[cols].apply(lambda x: x.str.normalize('NFKD').str.encode('ascii', errors='ignore').str.decode('utf-8'))
def split_dist(select_df, dist_col): for i in range(len(select_df)): District = select_df[dist_col][i] District = District.split() if len(District) == 2: State = District[0] Dis_Num = District[1] elif len(District) == 3: State = District[0] + ' ' + District[1] Dis_Num= District[2] select_df['State'][i] = State select_df['Dis_Num'][i] = Dis_Num
def last_name_split(select_df, split_column, delim): for i in range(len(select_df)): name = select_df[split_column][i] name = name.split(delim) if len(name) == 2: first_name = name_norm(name[1]) last_name = name[0] elif len(name) == 3: first_name = name_norm(name[1]) + ' ' + name_norm(name[2]) last_name = name[0] else: first_name = name_norm(name[1]) + ' ' + name_norm(name[2]) + ' ' + name_norm(name[3]) last_name = name[0] select_df['Last Name'][i] = last_name select_df['First Name'][i] = first_name select_df['Full Name'][i] = first_name + ' ' + last_name
def first_name_split(select_df, split_column): for i in range(len(select_df)): name = select_df[split_column][i] name = name.split() if len(name) == 2: first_name = name_norm(name[0]) last_name = name[1] elif len(name) == 3: first_name = name_norm(name[0]) + ' ' + name_norm(name[1]) last_name = name[2] elif len(name) == 4: first_name = name_norm(name[0]) + ' ' + name_norm(name[1]) + ' ' + name_norm(name[2]) last_name = name[3] elif len(name) == 5: first_name = name_norm(name[0]) + ' ' + name_norm(name[1]) + ' ' + name_norm(name[2]) + '' + name_norm(name[3]) last_name = name[4] else: first_name + first_name try: select_df['Last Name'][i] = last_name except: select_df['Last Name'][i] = first_name select_df['First Name'][i] = first_name select_df['Full Name'][i] = first_name + ' '+ last_name
def insert_data(to_df, from_df, check_column, check_var, from_column, target_column, target_var): to_df.loc[to_df[check_column]== check_var, target_column] = from_df.loc[from_df[check_column] == target_var, from_column].values[0]
def newest(path): files = os.listdir(path) paths = [os.path.join(path, basename) for basename in files] return max(paths, key=os.path.getctime)
def find_replace(table, column, find, replace): table[column] = table[column].str.replace(find,replace)
def text_replace (select_df, column_name, original, new): select_df[column_name]=select_df[column_name].str.replace(original, new)
def id_find(select_df): for one_name in select_df['Full Name']: select_df = select_df linked_name = process.extract(one_name, joint_df['Full Name'], limit = 1, scorer=fuzz.token_set_ratio) linked_name = str(linked_name) linked_name = re.sub(r"[[](')]", '', linked_name) linked_name = linked_name.split(', ') linked_name = linked_name[0] insert_data(select_df, joint_df, 'Full Name', one_name, 'Fec_ID', 'Fec_ID', linked_name) return select_df
def race_rating(url, category, target_df, rate_cat): rate_soup = bs(rate_page.text, 'html') rate_table = rate_soup.find(id = category) rate_headers = rate_table.find_all('div', class_ ='popup-table-data-cell') rate_data = rate_table.find_all('div',class_='popup-table-data-row') for row in rate_data[1:]: row_data = row.find_all('div',class_='popup-table-data-cell') indy_row = [data.text.strip() for data in row_data] row = list(filter(None,[data.string.strip() for data in row])) row.insert(3,rate_cat) length = len(target_df) target_df.loc[length] = row
Import/Clean FEC Canidate List
REQ = requests.get(fec_url, verify=False) with open('fec_names.zip','wb') as OUTPUT_FILE: OUTPUT_FILE.write(REQ.content)
with zipfile.ZipFile ('fec_names.zip', 'r') as ZIP_REF: ZIP_REF.extractall ('D:\MemberUpdate')
os.remove('fec_names.zip')
FEC List Clean and organize
fec_df = pd.read_csv('D:\MemberUpdate\weball26.txt', sep = '|', header = None, names= fec_columns, encoding = 'latin1') fec_df_true = fec_df.drop_duplicates(subset=['CAND_NAME'], keep='first')
text_norm(fec_df) name_column_clean(fec_df, 'CAND_NAME') name_insert_column(fec_df) last_name_split(fec_df, 'CAND_NAME',', ') name_lower_case(fec_df)
Get Current House Members from WIKI
house_page = requests.get(house_url,verify=False) house_soup = bs(house_page.text, 'html') house_table = house_soup.find('table', class_='wikitable', id = 'votingmembers') house_table_headers = house_table.find_all('th')[:8] house_table_titles = [title.text.strip() for title in house_table_headers] house_table_titles.insert(2,'go_away')
house_df = pd.DataFrame(columns= house_table_titles) column_data = house_table.find_all('tr')[1:] house_table_names = house_table.find_all('th')[11:] house_table_test = [title.text.strip() for title in house_table_names]
for row in column_data: row_data = row.find_all('th') indy_row_data = [data.text.strip() for data in row_data] for name in indy_row_data: row_data = row.find_all('td') table_indy = [data.text.strip() for data in row_data] if table_indy[0] == 'Vacant': table_indy= ['Vacant Vacant', 'Vacant', 'Vacant', 'Vacant', 'Vacant', 'Vacant', 'Vacant', 'Vacant'] full_row = indy_row_data + table_indy length = len(house_df) house_df.loc[length] = full_row
Clean/Normalize House Wiki List
text_norm (house_df) name_column_clean(house_df, 'Member') house_df = house_df.rename(columns={"Born[4]": "Born"}) house_df["Born"] = house_df["Born"].str.split(')').str[0] text_replace(house_df, 'Born', '(', '') text_replace(house_df, 'Party', 'Democratic', 'DEM') text_replace(house_df, 'Party', 'Independent','IND') text_replace(house_df, 'Party', 'Republican','REP') column_clean(house_df, 'Party', r'(.)') column_clean(house_df, 'Party', r'[.]') column_clean(house_df, 'Assumed office', r'[.*]')
Split and add districts
insert_column(house_df,1,'Dis_Num') insert_column(house_df,1,'State') split_dist(house_df, 'District') text_replace(house_df, 'Dis_Num', 'at-large', '00') house_df['Dis_Num'] = pd.to_numeric(house_df['Dis_Num']) house_df['State'] = house_df['State'].str.strip().replace(state2abbrev)
Split out Last name and add to wiki List
name_insert_column(house_df)
first_name_split(house_df,'Member')
name_lower_case(house_df)
insert_column(house_df, 1, 'Fec_ID')
Match the House names
for one_name in house_df['Full Name']: fec_df_test = fec_df fec_df_test = fec_df_test[fec_df_test['Fec_ID'].str.startswith("H")] fec_df_test = fec_df_test[fec_df_test['CAND_OFFICE_DISTRICT'] == house_df.loc[house_df['Full Name'] == one_name, 'Dis_Num' ].values[0]]
fec_df_test = fec_df_test[fec_df_test['CAND_OFFICE_ST'] == house_df.loc[house_df['Full Name'] == one_name, 'State' ].values[0]] linked_name = process.extract(one_name, fec_df_test['Full Name'], limit = 2, scorer=fuzz.token_set_ratio) linked_name = str(linked_name) linked_name = re.sub(r"[[](')]", '', linked_name) linked_name = linked_name.split(', ') linked_name = linked_name[0] house_df.loc[house_df['Full Name']== one_name,'Fec_ID'] = fec_df_test.loc[fec_df['Full Name'] == linked_name, 'Fec_ID'].values[0]
house_df['Dis_Num'] = house_df['Dis_Num'].apply(lambda x: '{0:0>2}'.format(x)) house_df.loc[house_df['Full Name'] == 'vacant vacant', 'Fec_ID'] = 'Vacant' house_df=house_df.drop(columns=['Residence', 'District', 'Prior experience', 'go_away'])
Get Current Senate Members from WIKI
senate_page = requests.get(senate_url,verify=False) senate_soup = bs(senate_page.text, 'html') senate_table = senate_soup.find('table', class_='wikitable', id = 'senators') senate_table_headers = senate_table.find_all('th')[:11] senate_table_titles = ['Member'] senate_table_titles = [title.text.strip() for title in senate_table_headers] senate_table_titles.insert(0,'Member') senate_df = pd.DataFrame(columns= senate_table_titles) column_data = senate_table.find_all('tr')[1:] sen_table_names = senate_table.find_all('th')[11:] sen_table_test = [title.text.strip() for title in sen_table_names]
all_rows = [] for row in column_data: row_data = row.find_all('th') indy_row_data = [data.text.strip() for data in row_data]
for name in indy_row_data:
row_data = row.find_all('td')
table_indy = [data.text.strip() for data in row_data]
if len(table_indy) == 11:
state = table_indy[0]
if len(table_indy) == 10:
table_indy.insert(0,state)
full_row = indy_row_data + table_indy
length = len(senate_df)
senate_df.loc[length] = full_rowClean/Normalize Senate Wiki List
text_norm (senate_df) senate_df = senate_df.rename(columns={"Born[4]": "Born"}) senate_df["Born"] = senate_df["Born"].str.split(')').str[0] name_column_clean(senate_df, 'Member') text_replace(senate_df, 'Born', '(', '') text_replace(senate_df, 'Party', 'Democratic', 'DEM') text_replace(senate_df, 'Party', 'Independent','IND') text_replace(senate_df, 'Party', 'Republican','REP') column_clean(senate_df, 'Party', r'(.)') column_clean(senate_df, 'Party', r'[.]') column_clean(senate_df, 'Assumed office', r'[.]') senate_df["Next Cycle"] = senate_df['Class'].str.slice(stop = 4) senate_df["Class"] = senate_df['Class'].str.slice(start = 4) text_replace(senate_df, 'Class','\n','' ) column_clean(senate_df, 'Class', r'[.]') senate_df['State'] = senate_df['State'].str.strip().replace(state2abbrev)
Split out Last name and add to wiki List
name_insert_column(senate_df) insert_column(senate_df,1,'Dis_Num') insert_column(senate_df, 1, 'Fec_ID') first_name_split(senate_df,'Member') name_lower_case(senate_df)
Match the Senate names
for one_name in senate_df['Full Name']:
fec_df_test = fec_df fec_df_test = fec_df_test[fec_df_test['Fec_ID'].str.startswith('S')] fec_df_test = fec_df_test[fec_df_test['CAND_OFFICE_ST'] == senate_df.loc[senate_df['Full Name'] == one_name, 'State' ].values[0]] linked_name = process.extract(one_name, fec_df_test['Full Name'], limit = 1, scorer=fuzz.token_set_ratio) linked_name = str(linked_name) linked_name = re.sub(r"[[](')]", '', linked_name) linked_name = linked_name.split(', ') linked_name = linked_name[0]
insert_data(senate_df, fec_df_test, 'Full Name', one_name, 'Fec_ID', 'Fec_ID', linked_name)
insert_data(senate_df, senate_df, 'Full Name', one_name, 'Next Cycle','Dis_Num', one_name)Combine Senate and House
senate_df.loc[senate_df['Full Name'] == 'vacant vacant', 'Fec_ID'] = 'Vacant' senate_df=senate_df.drop(columns=['Portrait', 'Previous electiveoffice(s)', 'Occupation(s)','Senator', 'Residence[4]', 'Class']) senate_df = senate_df[['Member', 'Fec_ID','State','Dis_Num', 'Full Name', 'Party', 'First Name', 'Last Name', 'Born', 'Assumed office']] house_df = house_df[['Member', 'Fec_ID','State','Dis_Num', 'Full Name', 'Party', 'First Name', 'Last Name', 'Born', 'Assumed office']] joint_df = pd.concat([senate_df, house_df], axis = 0) joint_df['Com_Dist'] = joint_df['State'] + joint_df['Dis_Num'] vacant_seats = joint_df.loc[joint_df['Member'] == 'Vacant Vacant', 'Com_Dist'].values
Get Bill Info
bills_df = pd.read_csv('D:\MemberUpdate\Bills.csv', engine = 'python', dtype= str) bills_df = bills_df[bills_df.columns.drop(list(bills_df.filter(regex='Unnamed')))] bills_df.rename(columns={'SB1467 | A bill to amend the Fair Credit Reporting Act to prevent consumer reporting agencies from f':'SB1467 | A bill to amend the Fair Credit Reporting Act'}, inplace=True)
for one_column in bills_df.columns: bills_df[one_column] = bills_df[one_column].replace('Co-Sponsor',f'{one_column} ~ Co-Sponsor')
for one_column in bills_df.columns: bills_df[one_column] = bills_df[one_column].replace('Primary Sponsor',f'{one_column} ~ Primary Sponsor')
HEADERS = bills_df.columns LIST = bills_df.columns.drop(['Dist','MOC','Party']) length = len(LIST) numbers = list(range(length+1)) del[numbers[0]]
bills_df = bills_df.replace('nan','') bills_df['Combined'] = bills_df.apply(lambda x: '~'.join(x.dropna().astype(str)),axis=1)
bills_df = bills_df.Combined.str.split("~",expand=True)
writer = pd.ExcelWriter(path='Bills.xlsx', engine='openpyxl', mode='a', if_sheet_exists='overlay') bills_df.to_excel(writer,sheet_name='Aristotle', index=False)
new_names.extend([f'B{n}' for n in numbers]) new_names.extend([f'B{n}V' for n in numbers])
bills_df = pd.DataFrame(columns=list(new_names))
bills_df.to_excel(writer,sheet_name='Aristotle', index=False)
writer.close()
bills_df = pd.read_excel('Bills.xlsx', sheet_name='Aristotle') bills_df = bills_df.dropna(thresh = .5, axis=1)
Clean/Normalize Bills List
text_norm (bills_df) name_column_clean(bills_df, 'MOC')
Split out Last name and add to wiki List
name_insert_column(bills_df) insert_column(bills_df, 1, 'Fec_ID') insert_column(bills_df, 1, 'State') insert_column(bills_df, 1, 'Dis_Num' ) first_name_split(bills_df, 'MOC')
name_lower_case(bills_df)
bills_df = bills_df[bills_df['Dist']!= 'HD-DC']
for one_name in bills_df['Full Name']: bills_df_test = bills_df linked_name = process.extract(one_name, joint_df['Full Name'], limit = 1, scorer=fuzz.token_set_ratio) linked_name = str(linked_name) linked_name = re.sub(r"[[](')]", '', linked_name) linked_name = linked_name.split(', ') linked_name = linked_name[0] insert_data(bills_df_test, joint_df, 'Full Name', one_name, 'Fec_ID', 'Fec_ID', linked_name)
Merge Names and Bills
bills_df_test = bills_df_test.drop(columns=['Dist', 'Dis_Num', 'State', 'Full Name', 'Last Name', 'First Name', 'Party', 'MOC']) bills_merged = pd.merge(joint_df, bills_df_test, how='outer', on = 'Fec_ID')
Get Committee Downloaded File
driver = webdriver.Chrome() driver.get(https://www.bgov.com/ga/directories/members-of-congress) element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "input-14")))
password = driver.find_element(By.ID, "input-13") password.send_keys(BGOV_USERNAME)
password = driver.find_element(By.ID, "input-14") password.send_keys(BGOV_PASSWORD)
driver.find_element(By.CSS_SELECTOR, "#app > div > div.content-wrapper > div > div.over-grid-content > div > div.content-area > form > button").click() time.sleep(1) element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#directories-download-slideout"))) time.sleep(1) driver.find_element(By.XPATH, "//[@id='directories-download-slideout']").click() time.sleep(1) element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//[@id='app']/div/div/div/div/m-modal[2]/div[2]/div/div[5]/div[2]"))) time.sleep(.5)
driver.find_element(By.XPATH, "//*[@id='app']/div/div/div/div/m-modal[2]/div[2]/div/div[5]/div[2]").click()
time.sleep(5)
driver.close()
report = newest('c:\Users\Downloads\')
committees_df = pd.read_csv(report, engine = 'python', dtype= str, usecols=['Display Name', 'Party Code','State', 'District', 'Leadership Position','Committees','SubCommittees' ])
for one_nstate in not_states:
committees_df = committees_df[committees_df['State']!=one_nstate]
for one_dis in vacant_seats: committees_df = committees_df[committees_df['District']!=one_dis]
Committee Expand and organization
find_replace(committees_df, 'Committees', ', ', '~') com = committees_df.join(committees_df['Committees'].str.split(",",expand=True)) for one_column in com.columns: com[one_column] = com[one_column].str.replace('~',', ')
com = com.drop(columns=['Committees', 'SubCommittees'])
Com_Length = list(range(len(com.columns)-4))
for one_number in Com_Length: Com_Names.append(f'C{one_number}')
Full_Com_Name = ['Display Name', 'Party Code','State', 'District', 'Leadership Position'] + Com_Names[1:] com.columns = Full_Com_Name
for one_name in Com_Names: number = Com_Names.index(one_name) com.insert(number+number+5, f'{one_name}L','') com =com.drop(columns=['C0L'])
Com_Names = Com_Names[1:] for one_name in Com_Names: try: com[[one_name, f'{one_name}L']] = com[one_name].str.split('(', expand=True, n = 1) text_replace (com, f'{one_name}L', ')', '')
except:
one_nameSubCommittee Expand and organization
find_replace(committees_df, 'SubCommittees', ', ', '~')
sub = committees_df.join(committees_df['SubCommittees'].str.split(",",expand=True)) for one_column in sub.columns: sub[one_column] = sub[one_column].str.replace('~',', ')
sub =sub.drop(columns=['Committees', 'SubCommittees'])
Sub_Length = list(range(len(sub.columns)-4))
for one_number in Sub_Length: Sub_Names.append(f'SC{one_number}')
Full_Sub_Name = ['Display Name', 'Party Code','State', 'District', 'Leadership Position'] + Sub_Names[1:] sub.columns = Full_Sub_Name
for one_name in Sub_Names: number = Sub_Names.index(one_name) sub.insert(number+number+5, f'{one_name}L','') sub =sub.drop(columns=['SC0L', 'Party Code', 'State', 'District', 'Leadership Position'])
Sub_Names = Sub_Names[1:] for one_name in Sub_Names: try: sub[[one_name, f'{one_name}L']] = sub[one_name].str.split('(', expand=True, n = 1) text_replace (sub, f'{one_name}L', ')', '')
except:
one_namecommittees_df = pd.merge(com, sub, how = 'outer', on = 'Display Name') committees_df = committees_df.rename(columns={"Display Name": "MOC"})
Clean/Normalize Committee List
text_norm (committees_df) name_column_clean(committees_df, 'MOC')
Split out Last name and add to wiki List
name_insert_column(committees_df) insert_column(committees_df, 1, 'Fec_ID')
first_name_split(committees_df,'MOC')
name_lower_case(committees_df)
committees_df = committees_df.sort_values('C1') committees_df = committees_df.drop_duplicates(subset=['District'], keep= 'first')
id_find(committees_df)
committees_df=committees_df.drop(columns=['MOC', 'Full Name', 'Last Name', 'First Name', 'Party Code', 'State', 'District']) committees_merged = pd.merge(bills_merged, committees_df, how='outer', on = 'Fec_ID')
committees_merged.to_csv('D:\MemberUpdate\billsandcommittees.csv', index = False, encoding = 'utf-8')
HOUSE RACE RATING
rate_page = requests.get(house_race_url,verify=False) rate_soup = bs(rate_page.text, 'html') rate_table = rate_soup.find(id = 'modal-from-table-likely-d') rate_headers = rate_table.find_all('div', class_ ='popup-table-data-cell') rate_titles = [title.text.strip() for title in rate_headers][:3] rate_titles.insert(3,'RATINGS') hrate_df = pd.DataFrame(columns= rate_titles)
for one_cat in house_cats: race_rating(house_race_url, one_cat, hrate_df, house_rate_cat[one_cat])
committees_merged['DISTRICT'] = committees_merged['Com_Dist'] hrate_df['DISTRICT'] = hrate_df['DISTRICT'].str.replace('[\w\s]','',regex=True) committees_merged.to_csv('D:\MemberUpdate\test.csv', index = False, encoding = 'utf-8')
text_norm(hrate_df) name_column_clean(hrate_df, 'REPRESENTATIVE') name_insert_column(hrate_df) insert_column(hrate_df, 1, 'Fec_ID')
first_name_split(hrate_df,'REPRESENTATIVE') name_lower_case(hrate_df) id_find(hrate_df)
hrate_df = hrate_df[hrate_df['REPRESENTATIVE'].str.contains('OPEN |VACANT') == False] hrate_df = hrate_df[hrate_df['REPRESENTATIVE'].str.contains('Vacant') == False]
committees_merged.to_csv('D:\MemberUpdate\billsandcommittees.csv', index = False, encoding = 'utf-8')
SENATE RACE RATING
srate_df = pd.DataFrame(columns= ['Names'])
rate_page = requests.get(senate_race_url,verify=False) rate_soup = bs(rate_page.text, 'html') srating = rate_soup.find_all('p',class_ = 'ratings-detail-page-table-7-column-cell-title') srating = [title.text.strip() for title in srating] rate_test = rate_soup.find_all('ul', class_='ratings-detail-page-table-7-column-ul')
for one_party in party: counter = 0 for one_sen in rate_test: data = one_sen.find_all('li', class_ = f'{one_party}-li-color') data = [title.text.strip() for title in data] rating = srating[counter] counter = counter + 1 for one_name in data: length= len(srate_df) srate_df.loc[length,'Names'] = one_name srate_df.loc[length, 'RATINGS'] = rating
srate_df[['State', 'Last Name']] = srate_df['Names'].str.split('-', n = 1, expand = True) srate_df['PVI'] = 'SEN' text_norm(srate_df) name_column_clean(srate_df, 'Last Name') insert_column(srate_df, 1, 'Fec_ID')
for one_name in srate_df['Last Name']: srate_df = srate_df linked_name = process.extract(one_name, joint_df['Last Name'], limit = 1, scorer=fuzz.token_set_ratio) linked_name = str(linked_name) linked_name = re.sub(r"[[](')]", '', linked_name) linked_name = linked_name.split(', ') linked_name = linked_name[0] insert_data(srate_df, joint_df, 'Last Name', one_name, 'Fec_ID', 'Fec_ID', linked_name)
srate_df=srate_df.drop(columns=['Names', 'PVI','State','Last Name']) hrate_df=hrate_df.drop(columns=['PVI','Last Name','Full Name','First Name']) comrate_df = pd.concat([srate_df, hrate_df], axis = 0) committees_merged = pd.merge(committees_merged, comrate_df, how='outer', on = 'Fec_ID') committees_merged.to_csv('D:\MemberUpdate\pvi.csv', index = False, encoding = 'utf-8')
r/PythonLearning • u/Mental-Ball5263 • Jul 26 '26
Week 2 of making an python teaching app with my frnd
Soo my last post some of u guys made me rethink the app , at first we were gonna make a simple app that will teach u that all , but i been kinda realised that there are good tutorials in python everywhere soo to keep up with these, i will redesign the teaching to make it more understanding and more like coding based with example and problem anyways,this app is really for myself,my frnds and stuff it's not like we expect it to next mimo or something and what does one more app gonna do to playstore But anyways i am more surprised that some people took time to look into my post and give their opinion and making me realise some things ,I am really grateful for that π
Anyways enough of my yapping soo this week I went through the basic lesson and redesigned the structure and also i realised that my current ui sucks soo i pick out some I think is okay can u guys tell me which is best for my opinion and suggest changes also plz ,that's all we did because we haven't gotten anytime to work on this project thx u for reading . There is two pic for each UI design one is homepage and other is learning overview (Btw idk much about anything still a student)
r/PythonLearning • u/Ill-Diet-7719 • Jul 14 '25
Help Request Code ain't coding (I'm a newbie)
r/PythonLearning • u/Healthy-Respond-6132 • Aug 21 '26
Showcase Iβm building a mobile app for learning Python
Iβve been working on NovaCode, an app for anyone who wants to learn and practice Python directly on their smartphone.
You can write and run Python code directly on your phone, create small projects, and learn step by step β without needing a computer.
The app is still actively being developed, and Iβd really appreciate your feedback. π
What features would you like to see in a mobile app for learning Python?
r/PythonLearning • u/xNicarox • Oct 19 '25
Help Request Hello, I would like to know if it is possible to create a fairly complete operating system in Python, specialized in cybersecurity.
Hello, I would like to know if it is possible to create a fairly complete operating system in Python, specialized in cybersecurity.
r/PythonLearning • u/zzzfirka • Mar 26 '25
Help me
I started my project not long ago, but I can't do anything.
r/PythonLearning • u/One-Type-2842 • Apr 02 '26
Is match ... case In Python Reliable as if .. elif .. else
What are your Views and Counterviews on match case condition checking In Python?
Are they Reliable as if elif else statement?
r/PythonLearning • u/Savings_Violinist117 • Apr 03 '26
Help Request i need to help....
I know the basics of Python, but I feel like I can't do anything without simple projects like: a calculator, password generator, rock paper scissors game, ........ What should I do now?
r/PythonLearning • u/thecoode • Dec 27 '24
Top 10 New JavaScript Frameworks and Libraries for 2025
r/PythonLearning • u/thecoode • Jan 12 '25
Can Python Handle 1 Billion Loops? Hereβs What Happens
r/PythonLearning • u/Good4ka • Dec 21 '24
I'm learning to program and I want to assemble a team and make my dream come true. Write to me if you can.
Hello everyone, this is my first post. I want to make a voice assistant and call it "vortex". I don't understand much only in Python who can help write in the comments how to contact you see you all soon π
r/PythonLearning • u/[deleted] • Dec 25 '24
Any programming site where i can solve coding challenges?
r/PythonLearning • u/salmaelh • Dec 26 '24
Don't know how to run code on VS code : hey guys, i am really new and trying to write a code using Python on VS code and I don't know how to run it, I have already installed the code runner and Python extensions but I have always the same error
r/PythonLearning • u/[deleted] • Oct 26 '23
99% Python Programmer Don't know this Trick
βοΈ Feel free to comment your thoughts and queries (Trust me it motivates me a lot ππ )
Don't forget to save π© it for later use (Or else you'll miss it π₯)
Also share π² it with your friends and colleagues out there (Let's help each other grow π )
Don't Forget To Like β€οΈ Share π² Save π©
coding #tech #python #javascripts #java #django #codeismylife #interview #gate #gateexam #interviewquestion #neet #jre
r/PythonLearning • u/clcodingupdates • 6d ago
Python Quiz of the day.
What will be the output of the following Python Code?
a, b = zip(*[(1, 2), (3, 4), (5, 6)])
print(sum(a) - sum(b))
r/PythonLearning • u/Top-Pressure3737 • 3d ago
Help Request I struggle to make a script that makes the curve of glucksmann's skull when we write his name
(Sorry Iβm french) I want to make a script on NumWorks calculator to display the function sqrt(x*(10-x)) + x/5 + 2 that traces the exact curvature of RaphaΓ«l Glucksmann's figure when writing his name. However, programming skills are very limited, I wrote some of it and the rest I did with chat gpt but I can't get it to work here is my script:
from math import *
from kandinsky import *
from ion import *
# Mots secrets et fonctions associees
def calcul(mot, x):
if mot == "glucksmann":
return sqrt(x*(10-x)) + x/5 + 2
else:
return None, "Fonction inconnue"
# Demander le mot
mot = input("Mot secret : ").lower()
# Effacer l'ecran
fill_rect(0, 0, 320, 222, (255, 255, 255))
# Calculer la fonction
test, equation = calcul(mot, 0)
if test is None:
print("Mot inconnu !")
else:
print("Fonction : " + equation)
# Parametres du graphique
xmin = -10
xmax = 10
ymin = -10
ymax = 10
# Conversion coordonnees
def pixel_x(x):
return int((x-xmin)*320/(xmax-xmin))
def pixel_y(y):
return int(180-(y-ymin)*180/(ymax-ymin))
# Axes
draw_string(equation, 5, 5, (0, 0, 255))
draw_line = None
# Axe horizontal
for i in range(320):
if i % 1 == 0:
set_pixel(i, pixel_y(0), (0, 0, 0))
# Axe vertical
for j in range(180):
set_pixel(pixel_x(0), j, (0, 0, 0))
# Tracer la courbe
ancien_x = None
ancien_y = None
for i in range(320):
x = xmin + i*(xmax-xmin)/319
y = calcul(mot, x)[0]
if y is not None and ymin <= y <= ymax:
px = pixel_x(x)
py = pixel_y(y)
if ancien_x is not None:
# Relier les points
dx = px - ancien_x
dy = py - ancien_y
n = max(abs(dx), abs(dy), 1)
for k in range(n+1):
xx = int(ancien_x + dx*k/n)
yy = int(ancien_y + dy*k/n)
if 0 <= xx < 320 and 0 <= yy < 180:
set_pixel(xx, yy, (0, 0, 255))
ancien_x = px
ancien_y = py
else:
ancien_x = None
ancien_y = None
r/PythonLearning • u/Hush_124 • Oct 15 '25
i need help
how do i modify a dictionary in dictionary. I tried something like this " cities['Dubai'] = 'Cape Town' ". i got an error
r/PythonLearning • u/Outrageous-Fish-8527 • Oct 06 '26
im making a "you are an idiot" adjecent peice of code and currently am trying to get this to work
im using thonny with python 3.1.4.4 and have pygame-ce downloaded
heres the error code.
Traceback (most recent call last):
File "<string>", line 10, in <module>
File "file location.py", line 555, in run
with Popen(*popenargs, **kwargs) as process:
File "file location.py", line 1039, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "file location.py", line 1553, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
and heres the code
import pygame
import sys
import time
import random
import os
import sys
import subprocess;
a = []
if len(sys.argv) == 1 or sys.argv[1] != "1":
pythonPath = subprocess.run(["which","python3"], capture_output=True).stdout.strip();
print("python at",pythonPath)
#The i is num of windows, it will open +1 extra. stopping the code will close just the extra window
for i in range(9):
proc = subprocess.Popen(
[pythonPath,os.path.realpath(__file__),"1"]
)
a.append(proc)
print("spawned window")
import pygame
import sys
import time
import random
import os
import sys
import subprocess;
a = []
if len(sys.argv) == 1 or sys.argv[1] != "1":
pythonPath = subprocess.run(["which","python3"], capture_output=True).stdout.strip();
print("python at",pythonPath)
#The i is num of windows, it will open +1 extra. stopping the code will close just the extra window
for i in range(9):
proc = subprocess.Popen(
[pythonPath,os.path.realpath(__file__),"1"]
)
a.append(proc)
print("spawned window")
import pygame
import sys
import time
import random
import os
import sys
import subprocess;
a = []
if len(sys.argv) == 1 or sys.argv[1] != "1":
pythonPath = subprocess.run(["which","python3"], capture_output=True).stdout.strip();
print("python at",pythonPath)
#The i is num of windows, it will open +1 extra. stopping the code will close just the extra window
for i in range(9):
proc = subprocess.Popen(
[pythonPath,os.path.realpath(__file__),"1"]
)
a.append(proc)
print("spawned window")
r/PythonLearning • u/Single_Cry8724 • Aug 09 '25
Bangladesh
How many bangladeshi python programmers on reedit ? Ok but
r/PythonLearning • u/asshishmeena96 • Sep 06 '25
In python how to create cases are cherry game ?
It's like a encryption decryption game . In which user provide message , shift_number as integer like how much the character shift in alfabets like user type A and shift by 2 then encrypted character will be C and encode_or_decode it a string for what you want encode or decode.
r/PythonLearning • u/hell0_boyz • Aug 13 '26
Discussion Cohort!!!!
Hi all,
I've been looking for curious minds to host a python cohort so that it would be great for those who were looking for better options to learn programming
This is not a mandatory meeting but those who are serious in programming can join
No problem if you are from non-cs background

