This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#List unique values in a DataFrame column | |
pd.unique(df.column_name.ravel()) | |
#Convert Series datatype to numeric, getting rid of any non-numeric values | |
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True) | |
#Grab DataFrame rows where column has certain values | |
valuelist = ['value1', 'value2', 'value3'] | |
df = df[df.column.isin(value_list)] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In my portfolio, I show how the popular Fama-MacBeth (1973) procedure is constructed in R. | |
# The procedure is used to estimate risk premia and determine the validity of asset pricing models. | |
# Google shows that the original paper has currently over 9000 citations (Mar 2015), making the methodology one of the most | |
# influential papers in asset pricing studies. It's used by thousands of finance students each year, but I'm unable to find a | |
# complete description of it from the web. | |
# | |
# While the methodology is not statistically too complex (although the different standard errors can get complex), | |
# it can pose some serious data management challenges to students and researchers. | |
# | |
# The goal of the methodology is to estimate risk premia in the financial markets. While newer, more sophisticated methods for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' --- | |
#' output: | |
#' html_document: | |
#' keep_md: TRUE | |
#' --- | |
#+ include = FALSE | |
library(dplyr) | |
#' Responses to [my |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(stringr) |
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 23 columns, instead of 14 in line 8.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
country,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011 | |
Abkhazia,,,,,,,,,,,,,,,,,,,,,, | |
Afghanistan,0,,,,,,,,,,,0.004188346,0.004092114,0.079875078,0.097163516,1.130397829,1.947423469,1.751202161,1.688485448,3.246305573,3.654114396,4.580669921 | |
Akrotiri and Dhekelia,,,,,,,,,,,,,,,,,,,,,, | |
Albania,0,,,,,0.011168695,0.032196828,0.048593919,0.06502737,0.081437045,0.114097347,0.325798377,0.390081273,0.971900415,2.420387798,6.043890864,9.609991316,15.03611541,23.86,41.2,45,49 | |
Algeria,0,,,,0.000360674,0.001768954,0.001738533,0.010268463,0.020238555,0.199523843,0.491705679,0.646114017,1.59164126,2.195359731,4.634475088,5.843942092,7.375984956,9.451190626,10.18,11.23,12.5,14 | |
American Samoa,0,,,,,,,,,,,,,,,,,,,,, | |
Andorra,0,,,,,,1.526601023,3.050175385,6.886209218,7.635686143,10.53883561,,11.26046872,13.54641288,26.83795439,37.60576622,48.936847,70.87,70.04,78.53,81,81 | |
Angola,0,,,,,,0.000775929,0.005673746,0.018453724,0.071964087,0.105045562,0.136013867,0.27037 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Replicating https://t.co/Jq1QfFGpjA | |
library(rvest) | |
library(stringr) | |
library(dplyr) | |
library(tidyr) | |
library(purrr) | |
library(lubridate) | |
get_and_clean_table <- function(url) { |