Homework 4: Creating graphs for my Project data (Project about Mars Craters - Part 1)
This project tries to find a correlation between the Diameter of a Crater and its depth. For more information please read my previous publications: Homework 3: Managing Data, Homework 2: Running my first Python Program about Mars Craters and Homework 1: Getting your Research Project Started. In this homework even though since the beginning of the Project I chose 3 points (Coordinates) with the only purpose of showing results, I am going to show only one of the three locations mentioned before. I put the Homework 4 in 3 publications because the Nature of this assignment.
PYTHON PROGRAM:
# -*- coding: utf-8 -*-
“”“ Created on Sun Apr 10 20:43:27 2016 @author: Rodolfo Lerma C
”“”
#FIRST PART OF THE CODE
import pandas import numpy mars = pandas.read_csv(‘marscrater_pds.csv’, low_memory=False) #upper-case all DataFrame column names - place afer code for loading data aboave mars.columns = map(str.upper, mars.columns) # bug fix for display formats to avoid run time errors - put after code for loading data above pandas.set_option('display.float_format’, lambda x:’%f’%x) #print(len(mars)) #number of observations (rows) #print(len(mars.columns)) # number of variables (columns) #setting variables you will be working with to numeric mars['DIAM_CIRCLE_IMAGE’] = mars['DIAM_CIRCLE_IMAGE’].convert_objects(convert_numeric=True) mars['DEPTH_RIMFLOOR_TOPOG’] = mars['DEPTH_RIMFLOOR_TOPOG’].convert_objects(convert_numeric=True) mars['LATITUDE_CIRCLE_IMAGE’] = mars['LATITUDE_CIRCLE_IMAGE’].convert_objects(convert_numeric=True) mars['LONGITUDE_CIRCLE_IMAGE’] = mars['LONGITUDE_CIRCLE_IMAGE’].convert_objects(convert_numeric=True)
print(’&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&’)
#1 SUBSET OF DATA print ('Latitude between -70 and -75 Degrees and Longitude between 20 and 15’) #Random Sample print (’———-Subset 1———’) sub1=mars[(mars['LATITUDE_CIRCLE_IMAGE’]<=-70) & (mars['LATITUDE_CIRCLE_IMAGE’]>=-75) & (mars['LONGITUDE_CIRCLE_IMAGE’]<=20) & (mars['LONGITUDE_CIRCLE_IMAGE’]>=15) & (mars['DEPTH_RIMFLOOR_TOPOG’] > 0)] #make a copy of my new subsetted data sub2 = sub1.copy() sub2['Diam_Subgroups’]=pandas.cut(sub2.DIAM_CIRCLE_IMAGE, [0, 5, 10, 16], labels=[“0-5 km”,“5-10 km”,“10-15 km”]) c4 = sub2['Diam_Subgroups’].value_counts(sort=False) p4 = sub2['Diam_Subgroups’].value_counts(sort=False, normalize=True) print(c4) print(p4) print (pandas.crosstab(sub2['Diam_Subgroups’], sub2['DIAM_CIRCLE_IMAGE’])) print (pandas.crosstab(sub2['Diam_Subgroups’], sub2['DEPTH_RIMFLOOR_TOPOG’]))
desc1 = sub2['DIAM_CIRCLE_IMAGE'].describe()
print (desc1)
desc2 = sub2['DEPTH_RIMFLOOR_TOPOG'].describe()
print (desc2)
bar1=seaborn.boxplot (x="DIAM_CIRCLE_IMAGE", data=sub2)
plt.xlabel('Diameter of the Creater')
plt.title('Diameter in Lat -70,-75 Long 20,15')
bar2=seaborn.boxplot(x="DEPTH_RIMFLOOR_TOPOG", data=sub2)
plt.xlabel('Depth of the Creater')
plt.title('Depth in Lat -70,-75 Long 20,15')
scat3 = seaborn.regplot(x=sub2["DIAM_CIRCLE_IMAGE"], y=sub2["DEPTH_RIMFLOOR_TOPOG"],data=mars)
plt.xlabel('Diameter of the Creater')
plt.ylabel('Depth of the Crater')
plt.title('Scatterplot for Diameter Vs Depth in Lat -70,-75 Long 20,15')
print(’&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&’)
#2 SUBSET OF DATA print ('Latitude between 35 and 30 Degrees and Longitude between 20 and 15’) #Random Sample print (’———-Subset 2———’) sub3=mars[(mars['LATITUDE_CIRCLE_IMAGE’]<=35) & (mars['LATITUDE_CIRCLE_IMAGE’]>=30) & (mars['LONGITUDE_CIRCLE_IMAGE’]<=20) & (mars['LONGITUDE_CIRCLE_IMAGE’]>=15) & (mars['DEPTH_RIMFLOOR_TOPOG’] > 0)] sub4 = sub3.copy() sub4['Diam_Subgroups_2’]=pandas.cut(sub4.DIAM_CIRCLE_IMAGE, [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 90], labels=[“0-5 km”,“5-10 km”,“10-15 km”,“15-20 km”,“20-25km”,“25-30 km”,“30-35 km”,“35-40 km”,“40-45 km”,“45-50 km”,“50-55 km”,“55-60 km”,“60-65 km”,“65-70 km”,“70-75 km”,“75-80 km”]) c6 = sub4['Diam_Subgroups_2’].value_counts(sort=False) p6 = sub4['Diam_Subgroups_2’].value_counts(sort=False, normalize=True) print(c6) print(p6)
print (pandas.crosstab(sub4['Diam_Subgroups_2’], sub4['DIAM_CIRCLE_IMAGE’])) print (pandas.crosstab(sub4['Diam_Subgroups_2’], sub4['DEPTH_RIMFLOOR_TOPOG’]))
print(’&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&’)
#3 SUBSET OF DATA print ('Latitude between 60 and 55 Degrees and Longitude between 20 and 15’) #Random Sample print (’———-Subset 3———’) sub5=mars[(mars['LATITUDE_CIRCLE_IMAGE’]<=60) & (mars['LATITUDE_CIRCLE_IMAGE’]>=55) & (mars['LONGITUDE_CIRCLE_IMAGE’]<=20) & (mars['LONGITUDE_CIRCLE_IMAGE’]>=15) & (mars['DEPTH_RIMFLOOR_TOPOG’] > 0)] sub6 = sub5.copy() sub6['Diam_Subgroups_3’]=pandas.cut(sub6.DIAM_CIRCLE_IMAGE, [0, 5, 10, 15, 20, 30], labels=[“0-5 km”,“5-10 km”,“10-15 km”,“15-20 km”,“20-25km”]) c8 = sub6['Diam_Subgroups_3’].value_counts(sort=False) p8 = sub6['Diam_Subgroups_3’].value_counts(sort=False, normalize=True) print(c8) print(p8)
print (pandas.crosstab(sub6['Diam_Subgroups_3’], sub6['DIAM_CIRCLE_IMAGE’])) print (pandas.crosstab(sub6['Diam_Subgroups_3’], sub6['DEPTH_RIMFLOOR_TOPOG’]))
print(’&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&’)











