This file contains hidden or 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
/* Import the CSV */ | |
FILENAME Gov_C "/folders/myfolders/Assignments/governors_county.csv"; | |
PROC IMPORT DATAFILE=Gov_C DBMS=CSV OUT=WORK.Gov_C_SAS; | |
GETNAMES=YES; | |
RUN; | |
/* freq procedure */ | |
proc freq data=Gov_C_SAS; |
This file contains hidden or 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
# Import Pandas | |
import pandas as pd | |
# Import CSV | |
data = pd.read_csv("../input/us-election-2020/governors_county.csv"); | |
# Frequencies in Actual Order | |
datax = data['state'].value_counts().sort_index() | |
# Create a dataframe |
This file contains hidden or 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
/* Proc freq with descending order */ | |
proc freq data=Gov_C_SAS order=freq; | |
tables state; | |
run; |
This file contains hidden or 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
datax = data['state'].value_counts() | |
datay = pd.DataFrame({ | |
'state': datax.index, | |
'Frequency': datax.values, | |
'Percent': ((datax.values/datax.values.sum())*100).round(2), | |
'Cumulative Frequenc': datax.values.cumsum(), | |
'Cumulative Percen':((datax.values.cumsum()/datax.values.sum())*100).round(2) | |
}) | |
datay |
This file contains hidden or 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
proc freq data = Gov_C_SAS; | |
tables state / nopercent nocum; | |
run; |
This file contains hidden or 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
datax = data['state'].value_counts().sort_index() | |
datay = pd.DataFrame({ | |
'state': datax.index, | |
'Frequency': datax.values | |
}) | |
datay |
This file contains hidden or 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
proc freq data=Gov_C_SAS; | |
tables county*state / norow nocol nopercent; | |
run; |
This file contains hidden or 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
datab = pd.crosstab(data.county, data.state, margins=True, margins_name='Total') | |
datab |
This file contains hidden or 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
/* freq procedure with missing */ | |
proc freq data=Gov_C_SAS; | |
tables GENRE / missing; | |
run; |
This file contains hidden or 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
datax = data['GENRE'].value_counts(dropna=False) | |
datay = pd.DataFrame({ | |
'GENRE': datax.index, | |
'Frequency': datax.values, | |
'Percent': ((datax.values/datax.values.sum())*100).round(2), | |
'Cumulative Frequency': datax.values.cumsum(), | |
'Cumulative Percent': ((datax.values.cumsum()/datax.values.sum())*100).round(2) | |
}) | |
datay |