“`python
import pandas
import numpy
“`

“`python
#Using the pandas code library to read in the data
craterdata = pandas.read_csv(‘./Coursera/marscrater_pds.csv’, low_memory = False)

#Ensuring that numeric variables with missing data are still considered numeric by Python
craterdata[‘LATITUDE_CIRCLE_IMAGE’]=craterdata[‘LATITUDE_CIRCLE_IMAGE’].convert_objects(convert_numeric=True)
craterdata[‘NUMBER_LAYERS’]=craterdata[‘NUMBER_LAYERS’].convert_objects(convert_numeric=True)

# Note: Dummy values were not assigned in the dataset for the variable MORPHOLOGY_EJECTA_1,
# so it is not numeric, but rather some kind of string/text variable

“`

“`python
#Seeing how much data is in the dataset
print(“Number of craters in the data set:”)
print(len(craterdata))

print(“Number of variables associated with the craters:”)
print(len(craterdata.columns))

print (“- – – – – – – – – – -“)
print (“- – – – – – – – – – -“)

#Exploring the distribution of craters with respect to their number of layers

print(“Count the number of craters with 0, 1, 2, 3, 4 and 5 layers:”)
c1 = craterdata[‘NUMBER_LAYERS’].value_counts(sort=False, dropna=False)
print (c1)

#NOTE: The sum of these counts = len(craterdata), so there is no missing data in this column

print(“Percentages of the craters that have 0, 1, 2, 3, 4 and 5 layers:”)
p1 = craterdata[‘NUMBER_LAYERS’].value_counts(sort=False, normalize=True)
print (p1*100)

print (“- – – – – – – – – – -“)
“`

Number of craters in the data set:
384343
Number of variables associated with the craters:
10
– – – – – – – – – – –
– – – – – – – – – – –
Count the number of craters with 0, 1, 2, 3, 4 and 5 layers:
0 364612
1 15467
2 3435
3 739
4 85
5 5
Name: NUMBER_LAYERS, dtype: int64
Percentages of the craters that have 0, 1, 2, 3, 4 and 5 layers:
0 94.866304
1 4.024270
2 0.893733
3 0.192276
4 0.022116
5 0.001301
Name: NUMBER_LAYERS, dtype: float64
– – – – – – – – – – –

“`python
#Exploring the distribution of craters with respect to their ejecta morphologies

print(“Counts of the total number of craters with specific ejecta morphologies:”)
c2 = craterdata[‘MORPHOLOGY_EJECTA_1’].value_counts(sort=False, dropna=False)
print (c2)

print(“Percentages of the total number of craters with specific ejecta morphologies:”)
p2 = craterdata[‘MORPHOLOGY_EJECTA_1’].value_counts(sort=False, normalize=True)
print (p2*100)

print (“- – – – – – – – – – -“)

#Exploring the crater distributions at different latitudes

print (“Using pandas.cut function to bin craters into latitude ranges”)
print(”)
print(“Counts for the number of craters in each latitude range displayed in columns by number of layers”)
sublat=craterdata[(craterdata[‘LATITUDE_CIRCLE_IMAGE’]>-90) & (craterdata[‘NUMBER_LAYERS’]>=0)]
sublat[‘LATITUDE_RANGE’] = pandas.cut(sublat.LATITUDE_CIRCLE_IMAGE,[-90, -60, -30, 0, 30, 60, 90])

print(pandas.crosstab(sublat[‘LATITUDE_RANGE’], sublat[‘NUMBER_LAYERS’]))
“`

Counts of the total number of craters with specific ejecta morphologies:
MLERC/MLERS/MLEPS 1
Rd/SLERCPd 1
DLEPC/DLEPSPd 3
MLERC/MLEPS/MLEPS 1
DLERSRd 2
Rd/DLEPC/DLEPS 52
SLErS 1
DLEPC/DLERC 11
DLEPC/DLERS 86
Rd/MLEPC 2
Rd/MLEPS 25
Rd/SLEPCRd 1
RD/SLEPC 1
DLERC/Rd/DLERS 3
Rd/SPERS 1
DLEPSPd 2
DLERCPd 5
Pd 2
MLERC/MLERC/MLEPS 5
Rd/MLERC/MLEPC/MLERS 1
DLEPCPd/DLEPSPd 1
MLEPC/MLEPC/MLEPS 1
Rd 24892
339718
Rd/MLERS/Rd 1
DLEPC/DLERSRd 1
SLERCPd 10
MLERS/MLERS/Rd/MLEPS 1
SLERSPd 16
MLERC/MLERS/MLERS/Rd 2

MLEPC/MLEPS/MLERS 1
DLERC/Rd 6
MLERS/MLEPC/MLERS 1
SLEPCPd 74
SLERS/Rd/SLERS 1
SLEPSPd 51
DLERC/DLEPC/Rd 1
SLEPSPd/Rd 1
DLEPC/DPEPCPd 1
Rd/DLEPC 32
Rd/DLEPS 137
DLERCPd/DLERSPd 1
MLEPS/MLERS/MLERS 4
DLERS/DLERC 1
DLEPS/DLERS/Rd 3
MLEPC/MLERS/MLERS 2
DLERS/Rd/DLEPS 2
DLERC/DLERS 110
DLEPCPd/DLERCPd 1
MLEPS 37
MLEPC 2
Rd/DLERC/DLERSRd 1
SLEPC/SLEPS 3
Rd/DLERC/DLEPS 11
Rd/DLERC/DLEPC 3
DLEPC/DLEPS/Rd 2
DLEPC/Rd/DLERS 1
Rd/MLERC/MLERS/MLERS 2
Rd/SLERS 555
Rd/SLERC 130
Name: MORPHOLOGY_EJECTA_1, dtype: int64
Percentages of the total number of craters with specific ejecta morphologies:
MLERC/MLERS/MLEPS 0.000260
Rd/SLERCPd 0.000260
DLEPC/DLEPSPd 0.000781
MLERC/MLEPS/MLEPS 0.000260
DLERSRd 0.000520
Rd/DLEPC/DLEPS 0.013530
SLErS 0.000260
DLEPC/DLERC 0.002862
DLEPC/DLERS 0.022376
Rd/MLEPC 0.000520
Rd/MLEPS 0.006505
Rd/SLEPCRd 0.000260
RD/SLEPC 0.000260
DLERC/Rd/DLERS 0.000781
Rd/SPERS 0.000260
DLEPSPd 0.000520
DLERCPd 0.001301
Pd 0.000520
MLERC/MLERC/MLEPS 0.001301
Rd/MLERC/MLEPC/MLERS 0.000260
DLEPCPd/DLEPSPd 0.000260
MLEPC/MLEPC/MLEPS 0.000260
Rd 6.476507
88.389277
Rd/MLERS/Rd 0.000260
DLEPC/DLERSRd 0.000260
SLERCPd 0.002602
MLERS/MLERS/Rd/MLEPS 0.000260
SLERSPd 0.004163
MLERC/MLERS/MLERS/Rd 0.000520

MLEPC/MLEPS/MLERS 0.000260
DLERC/Rd 0.001561
MLERS/MLEPC/MLERS 0.000260
SLEPCPd 0.019254
SLERS/Rd/SLERS 0.000260
SLEPSPd 0.013269
DLERC/DLEPC/Rd 0.000260
SLEPSPd/Rd 0.000260
DLEPC/DPEPCPd 0.000260
Rd/DLEPC 0.008326
Rd/DLEPS 0.035645
DLERCPd/DLERSPd 0.000260
MLEPS/MLERS/MLERS 0.001041
DLERS/DLERC 0.000260
DLEPS/DLERS/Rd 0.000781
MLEPC/MLERS/MLERS 0.000520
DLERS/Rd/DLEPS 0.000520
DLERC/DLERS 0.028620
DLEPCPd/DLERCPd 0.000260
MLEPS 0.009627
MLEPC 0.000520
Rd/DLERC/DLERSRd 0.000260
SLEPC/SLEPS 0.000781
Rd/DLERC/DLEPS 0.002862
Rd/DLERC/DLEPC 0.000781
DLEPC/DLEPS/Rd 0.000520
DLEPC/Rd/DLERS 0.000260
Rd/MLERC/MLERS/MLERS 0.000520
Rd/SLERS 0.144402
Rd/SLERC 0.033824
Name: MORPHOLOGY_EJECTA_1, dtype: float64
– – – – – – – – – – –
Using pandas.cut function to bin craters into latitude ranges

Counts for the number of craters in each latitude range displayed in columns by number of layers
NUMBER_LAYERS 0 1 2 3 4 5
LATITUDE_RANGE
(-90, -60] 20211 817 95 18 0 1
(-60, -30] 74879 3148 575 114 15 0
(-30, 0] 128302 4334 698 220 27 2
(0, 30] 87342 3592 568 228 33 0
(30, 60] 44637 2469 1092 119 8 1
(60, 90] 9241 1107 407 40 2 1

“`python

“`

Advertisements