Closed Nikolas121205 closed 7 months ago
Hi Niko! 🙋🏻♂️
(if you read this from github, you'll see the code formatted)
All of the things that I'll comment are things that I would change to polish the project a little bit more.
About repo organization 📚
.ipynb_checkpoints
and .DS_Store
. They both are files that cache things into memory to make your computer go a bit faster. However, in a repo, it just causes noise. attacks.csv
file, the owners of the dataset do ask for you to ignore it, so you can include it in the .gitignore
file (which by the way, you're missing!)The README.md ✍🏻: The README.md is a crucial part of the repo. You do need to have one and the things that need to be in it are a bit like a scientific paper: Abstract, introduction, methodology, conclusions, etc. These sections are approximate, but pretty much you'd want your repo to be self-explanatory so that anyone with zero knowledge of data or programming would understand your whole project. You could also include images by embedding them in the markdown.
Modularization 📉: The python files within the src/
directory are empty. It's okay. For the next project it will be expected you do have them: both encapuslated code (functions) and modularized (into different python files).
The code 👩💻:
In this function:
def clean_colnames(df):
'''Clean columns names when passing a pandas dataframe: params (df - dataframe)'''
col_clean = []
for col in df.columns:
col = col.strip().lower()
col = col.replace('.',' ')
col_clean.append(col)
df.columns = col_clean
return df.columns
great that you put it into a function. You can refactor ir by doing:
def clean_colnames(df):
'''Clean columns names when passing a pandas dataframe: params (df - dataframe)'''
col_clean = []
for col in df.columns:
col = col.strip().lower()
col = col.replace('.',' ')
col_clean.append(col)
return df.col_clean
df.columns = clean_colnames(df)
instead of re-assigning inside of the function.
For this function:
def country_hem(col):
hem_lst = []
for i in col:
try:
country = CountryInfo(row)
except AttributeError:
row = 'x'
try:
pos = country.latlng()
except KeyError:
pos = (0,0)
if pos[0] > 0:
temp_row = 1
elif pos[0] < 0:
temp_row = 0
else:
temp_row = np.nan
hem_lst.append(temp_row)
return hem_lst
did you do an except AttributeError because you had missing values? I do find it to be a nice workaround, honestly. Another thing you could to is transform the nulls into something else, just in case. Or maybe drop them if you think it makes sense for the rest of the processing.
filter_5 = df_q1["month"] == "Mid"
if this is the case, having a lot of repeated lines that are similar, chances are you can (and should) refactor this. Maybe you can create a dictionary where you substitute keys by values. I'm sure you can put this into a function to drop those that you filter out.
In terms of plots: sort them either by count or alphabetically, as we mentioned in the presentation. And the rotation of the axis to increase readability. Also, try to avoid this by including a semicolon at the end of the plotting line:
list_to_delete = [6177,
6178,
6179,
6180,
6181,
6182,
6183,
6184,
...
I also see you're dropping missing values after creating a subset. If you do a prelimnary cleaning, you can just drop them once and then create subsets/copies and work with them, but you'll have done that once instead.
Anyways, all these things are simple things to change formally, but that functionally are okay. Meaning: the project is good, you can just do some small adjustments to make it a bit better.
Do include a readme.md though!!! That is not jsut a detail.
Good job though!
https://github.com/Nikolas121205/Project