# [Tutor] New Item

Sydney Shall s.shall at virginmedia.com
Sun Oct 15 07:52:59 EDT 2017

```On 28/09/2017 11:46, Peter Otten wrote:
> LARRYSTALEY07 at comcast.net wrote:
>
>> I am very new to Python and appreciate the input as I was able to fully
>> install Python with all needed libraries (i.e., numpy, pandas, etc.).
>> However, I now have an application question in needed to construct a 2D
>> Histogram.
>>
>> Basically, I have an Excel file that includes three columns:
>> Column 1 - Gender (Male or Female)
>> Column 2 - Height (in inches)
>> Column 3 - Hand Span (in inches)
>
> I have yet to grok your code samples, but my feeling is that your approach
> is too low-level. Do you mean something like
>
> http://matplotlib.org/examples/pylab_examples/hist2d_demo.html
>
> by "2d histograms"? That would require very little code written by yourself:
>
> import pandas as pd
> from matplotlib import pyplot
>
> filename = "size.xls"
> sheetname = "first"
>
>
> for index, sex in enumerate(["female", "male"], 1):
>      pyplot.figure(index)
>      subset = data[data["Gender"] == sex]
>      pyplot.hist2d(subset["Height"].values, subset["Hand Span"].values)
>
> pyplot.show()
>
>
>>
>>
>> X=np.array(data[:,1],dtype=float);
>> S=np.array(data[:,2],dtype=float);
>> T=np.array(data[:,0],dtype=str);
>>
>>
>>
>>
>> Finally, is my intended coding for the actual 2D histogram. I will get min
>> and max from the height and hand span arrays. Note I am still learning
>> Python and looping is new to me:
>>
>>
>>
>>
>> # Define histogram classifier to build histogram using two variables
>> def Build1DHistogramClassifier(X, S, smin, smax,T,B,xmin,xmax):
>> HF=np.zeros(B).astype('int32');
>> HM=np.zeros(B).astype('int32');
>> binindices1=(np.round(((B-1)*(X-xmin)/(xmax-xmin)))).astype('int32');
>> binindices2=(np.round(((B-1)*(S-smin)/(smax-smin)))).astype('int32');
>> for i,b in enumerate(binindices1):
>> for i,c in enumerate(bindindices2):
>> if T[i]=='Female':
>> HF[b,c]+=1;
>> else:
>> HM[b,c]+=1;
>> return [HF, HM]

Hi,

I have a similar problem, but my data is not in excel but is in
OpenOffice "Spreadsheet', but not in "Database".

My question is can I use a similar simple procedure as that given by
Peter Otten.

Ta muchly.

--
Sydney
```