-
Notifications
You must be signed in to change notification settings - Fork 0
/
Z - Final Pro - Non Quantitative, Quantitative.py
38 lines (28 loc) · 1.87 KB
/
Z - Final Pro - Non Quantitative, Quantitative.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
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 29 16:05:20 2021
@author: Jessica Brown
@position: Economics Intern at MARAD 06/2021 - 07/2021
@personal email: TreePerson586@yahoo.com
@school email: Jessica.Marie.Brown@live.mercer.edu
"""
#Import package
import pandas as pd
#Import data
ec2021 = pd.read_csv("ec2021.txt", delimiter = "|", dtype = {"Filing Port" : str, "Sequence" : str, "Arrival Port" : str, "Agent Name" : str, "Cargo Type Code" : str, "Last Domestic Port" : str, "Last Foreign Port" : str, "Via Port" : str, "Vessel Repair" : str, "Vessel Name" : str, "Call Sign Number" : str, "Official Registration Number" : str, "Built Country Code" : str, "IMO" : str, "Vessel Type" : str, "USCS Code" : str, "Owner Name" : str, "Operator Name" : str, "Operator Country Code" : str, "Registration Country Code" : str, "Clearance Date/Time" : str, "Create Date/Time" : str, "Update Date/Time" : str, "Entrance Date/Time" : str, "Arrival Date/Time" : str}, parse_dates = ["Update Date/Time", "Create Date/Time", "Clearance Date/Time", "Entrance Date/Time", "Arrival Date/Time"])
#Drop duplicate values
ec2021.drop_duplicates()
#First make DataFrame out of column you want to convert
on = ec2021[["Owner Name"]]
#Make it so every value only appears once
on.drop_duplicates()
#Create an empty dictionary for it
az = {}
#Assign each value to a number (its index number is the same as the label)
for label, row in enumerate(on.iterrows()):
az[on["Owner Name"][label]] = label
#Assign number values to it with loop
for label, row in enumerate(ec2021.iterrows()):
ec2021.loc[label, ["Owner Name Numbered"]] = az[ec2021["Owner Name"][label]]
#Make sure to save this as a new text file (.txt) or your choice so you don’t have to do this again
ec2021.to_csv = (header = True, index = False, path_or_buf = “C:/Users/TreeP/Desktop/Python/ec2021numbered.txt”)