Question

I have a question on a book "Python for Data Analysis" if anyone is interested in this book.

After running an example on page 244 (Plotting Maps: Visualizing Haiti Earthquake Crisis Data), my result of dummy_frame.ix doesn't look the same as what the book says as below:

dummy_frame = DataFrame(np.zeros((len(data), len(code_index))),
index=data.index, columns=code_index)

If all goes well, dummy_frame should look something like this:

In [107]: dummy_frame.ix[:, :6]
Out[107]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3569 entries, 0 to 3592
Data columns:
1 3569 non-null values
1a 3569 non-null values
1b 3569 non-null values
1c 3569 non-null values
1d 3569 non-null values
2 3569 non-null values
dtypes: float64(6)

My result is:

In [61]: dummy_frame.ix[:, :6]
Out[61]:
    1  1a  1b  1c  1d  2
0   0   0   0   0   0  0
4   0   0   0   0   0  0
5   0   0   0   0   0  0
6   0   0   0   0   0  0
7   0   0   0   0   0  0
<snip>
57  0   0   0   0   0  0
58  0   0   0   0   0  0
59  0   0   0   0   0  0
60  0   0   0   0   0  0
61  0   0   0   0   0  0
62  0   0   0   0   0  0
   .. ... ... ... ... ..

[3569 rows x 6 columns]

I checked its errata page but this is not mentioned in there. I ensured there is no typo of mine here and also ran it on two different machines but the result was the same.

Any advice please?

Edited:

Thanks dartdog, joris! I didn't notice the Dataframe display was changed. Now I can get the same result with .info()

In [5]: dummy_frame.ix[:, :6].info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3569 entries, 0 to 3592
Data columns (total 6 columns):
1     3569 non-null float64
1a    3569 non-null float64
1b    3569 non-null float64
1c    3569 non-null float64
1d    3569 non-null float64
2     3569 non-null float64
dtypes: float64(6)
Was it helpful?

Solution

That is the same result as far as I can see, Pandas has been changing the default display of dataframes, the example in the book is the summary display and the display you got is the newer format that displays the begin/ end.. read up on display options... In the appropriate version doc that you are using

OTHER TIPS

I'm new to programming and don't understand much of that code, however the problem may be the version of python you are running. Python 2.7 and 3.3 work differently and the book may be based on one while you are using the other. Check the versions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top