简体   繁体   中英

Different result of code example on book: Python for Data Analysis

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)

就我所知,这是相同的结果,Pandas一直在改变数据帧的默认显示,书中的例子是摘要显示,你得到的显示是显示开始/结束的新格式..读取显示选项...在您使用的相应版本文档中

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM