I'm pretty new to scripting, and here's my first code that I wrote. The purpose of the code is to extract a primary identification based on a secondary identification. I would appreciate some constructive criticism and aggressive checking. The codes work and do what they are supposed to do. But how can I make it more python? more passionate?
import codecs import numpy as np import pandas like pd def import_file (path): & # 39; & # 39; & # 39; import the .csv files as a panda data frame Args: path (csv file): take the path of the .csv file Returns: Returns a panda data frame & # 39; & # 39; & # 39; with codecs.open (path, "r", encoding = & # 39; utf-8 & # 39 ;, errors = & # 39; ignore & # 39;) as fdata: df = pd.read_csv (fdata) back df def appends_address_before_name (file): & # 39; & # 39; & # 39; Attach the address before the name ID name Returns: Returns the file, with the address attached to the name of the column. & # 39; & # 39; & # 39; case file['ID'] =[address+str(col)paracolenarchivo[address+str(col)forcolinfile[address+str(col)paracolenarchivo[address+str(col)forcolinfile['ID']]return file def create_parent_name (file, column_name: str): & # 39; & # 39; & # 39; This will create a parent name based on the ID column Args: File: Take the dataFrame created from the appends_address_before_name function column_name: take the name of the column where the father's name is will be extracted from. The logic is to divide it into the last point. [[parentname].[+ childname]]Returns: Returns a panda data frame with a new column called parentID & # 39; & # 39; & # 39; case file['parentID'] = [ x.rsplit('.', 1) If & # 39;. & # 39; in x else x[:-1] for x in the file[column_name] ]return file address = & # 39; New Jersey & # 39; file_1 = import_file (r & # 39; C: humans.csv & # 39;) file_2 = appends_address_before_name (file = file_1) file_3 = create_parent_name (file = file_2, & # 39; ID & # 39;) print (file_3)
The entry C.V is a column of values separated by decimal places such as the following
Also, it seems to me that the way I pass the variables between the functions at the end of the code seems quite basic and terrible. What can I improve in the previous code and how can I improve it?