Tweak display options in pandas
This introduction to pandas is derived from Data School's pandas Q&A with my own notes and code.
Changing display options in pandas¶
In [1]:
import pandas as pd
In [2]:
url = 'http://bit.ly/drinksbycountry'
drinks = pd.read_csv(url)
In [3]:
# this shows only the first and last 30 rows
drinks
Out[3]:
country | beer_servings | spirit_servings | wine_servings | total_litres_of_pure_alcohol | continent | |
---|---|---|---|---|---|---|
0 | Afghanistan | 0 | 0 | 0 | 0.0 | Asia |
1 | Albania | 89 | 132 | 54 | 4.9 | Europe |
2 | Algeria | 25 | 0 | 14 | 0.7 | Africa |
3 | Andorra | 245 | 138 | 312 | 12.4 | Europe |
4 | Angola | 217 | 57 | 45 | 5.9 | Africa |
5 | Antigua & Barbuda | 102 | 128 | 45 | 4.9 | North America |
6 | Argentina | 193 | 25 | 221 | 8.3 | South America |
7 | Armenia | 21 | 179 | 11 | 3.8 | Europe |
8 | Australia | 261 | 72 | 212 | 10.4 | Oceania |
9 | Austria | 279 | 75 | 191 | 9.7 | Europe |
10 | Azerbaijan | 21 | 46 | 5 | 1.3 | Europe |
11 | Bahamas | 122 | 176 | 51 | 6.3 | North America |
12 | Bahrain | 42 | 63 | 7 | 2.0 | Asia |
13 | Bangladesh | 0 | 0 | 0 | 0.0 | Asia |
14 | Barbados | 143 | 173 | 36 | 6.3 | North America |
15 | Belarus | 142 | 373 | 42 | 14.4 | Europe |
16 | Belgium | 295 | 84 | 212 | 10.5 | Europe |
17 | Belize | 263 | 114 | 8 | 6.8 | North America |
18 | Benin | 34 | 4 | 13 | 1.1 | Africa |
19 | Bhutan | 23 | 0 | 0 | 0.4 | Asia |
20 | Bolivia | 167 | 41 | 8 | 3.8 | South America |
21 | Bosnia-Herzegovina | 76 | 173 | 8 | 4.6 | Europe |
22 | Botswana | 173 | 35 | 35 | 5.4 | Africa |
23 | Brazil | 245 | 145 | 16 | 7.2 | South America |
24 | Brunei | 31 | 2 | 1 | 0.6 | Asia |
25 | Bulgaria | 231 | 252 | 94 | 10.3 | Europe |
26 | Burkina Faso | 25 | 7 | 7 | 4.3 | Africa |
27 | Burundi | 88 | 0 | 0 | 6.3 | Africa |
28 | Cote d'Ivoire | 37 | 1 | 7 | 4.0 | Africa |
29 | Cabo Verde | 144 | 56 | 16 | 4.0 | Africa |
... | ... | ... | ... | ... | ... | ... |
163 | Suriname | 128 | 178 | 7 | 5.6 | South America |
164 | Swaziland | 90 | 2 | 2 | 4.7 | Africa |
165 | Sweden | 152 | 60 | 186 | 7.2 | Europe |
166 | Switzerland | 185 | 100 | 280 | 10.2 | Europe |
167 | Syria | 5 | 35 | 16 | 1.0 | Asia |
168 | Tajikistan | 2 | 15 | 0 | 0.3 | Asia |
169 | Thailand | 99 | 258 | 1 | 6.4 | Asia |
170 | Macedonia | 106 | 27 | 86 | 3.9 | Europe |
171 | Timor-Leste | 1 | 1 | 4 | 0.1 | Asia |
172 | Togo | 36 | 2 | 19 | 1.3 | Africa |
173 | Tonga | 36 | 21 | 5 | 1.1 | Oceania |
174 | Trinidad & Tobago | 197 | 156 | 7 | 6.4 | North America |
175 | Tunisia | 51 | 3 | 20 | 1.3 | Africa |
176 | Turkey | 51 | 22 | 7 | 1.4 | Asia |
177 | Turkmenistan | 19 | 71 | 32 | 2.2 | Asia |
178 | Tuvalu | 6 | 41 | 9 | 1.0 | Oceania |
179 | Uganda | 45 | 9 | 0 | 8.3 | Africa |
180 | Ukraine | 206 | 237 | 45 | 8.9 | Europe |
181 | United Arab Emirates | 16 | 135 | 5 | 2.8 | Asia |
182 | United Kingdom | 219 | 126 | 195 | 10.4 | Europe |
183 | Tanzania | 36 | 6 | 1 | 5.7 | Africa |
184 | USA | 249 | 158 | 84 | 8.7 | North America |
185 | Uruguay | 115 | 35 | 220 | 6.6 | South America |
186 | Uzbekistan | 25 | 101 | 8 | 2.4 | Asia |
187 | Vanuatu | 21 | 18 | 11 | 0.9 | Oceania |
188 | Venezuela | 333 | 100 | 3 | 7.7 | South America |
189 | Vietnam | 111 | 2 | 1 | 2.0 | Asia |
190 | Yemen | 6 | 0 | 0 | 0.1 | Asia |
191 | Zambia | 32 | 19 | 4 | 2.5 | Africa |
192 | Zimbabwe | 64 | 18 | 4 | 4.7 | Africa |
193 rows × 6 columns
ROWS
In [4]:
# to show all rows go to the documentation Pandas.get_option
# use display.max_rows
# this is the default
pd.get_option('display.max_rows')
Out[4]:
60
In [6]:
# let's change to set_option to change
# be careful if you've many rows
pd.set_option('display.max_rows', None)
In [7]:
drinks
Out[7]:
country | beer_servings | spirit_servings | wine_servings | total_litres_of_pure_alcohol | continent | |
---|---|---|---|---|---|---|
0 | Afghanistan | 0 | 0 | 0 | 0.0 | Asia |
1 | Albania | 89 | 132 | 54 | 4.9 | Europe |
2 | Algeria | 25 | 0 | 14 | 0.7 | Africa |
3 | Andorra | 245 | 138 | 312 | 12.4 | Europe |
4 | Angola | 217 | 57 | 45 | 5.9 | Africa |
5 | Antigua & Barbuda | 102 | 128 | 45 | 4.9 | North America |
6 | Argentina | 193 | 25 | 221 | 8.3 | South America |
7 | Armenia | 21 | 179 | 11 | 3.8 | Europe |
8 | Australia | 261 | 72 | 212 | 10.4 | Oceania |
9 | Austria | 279 | 75 | 191 | 9.7 | Europe |
10 | Azerbaijan | 21 | 46 | 5 | 1.3 | Europe |
11 | Bahamas | 122 | 176 | 51 | 6.3 | North America |
12 | Bahrain | 42 | 63 | 7 | 2.0 | Asia |
13 | Bangladesh | 0 | 0 | 0 | 0.0 | Asia |
14 | Barbados | 143 | 173 | 36 | 6.3 | North America |
15 | Belarus | 142 | 373 | 42 | 14.4 | Europe |
16 | Belgium | 295 | 84 | 212 | 10.5 | Europe |
17 | Belize | 263 | 114 | 8 | 6.8 | North America |
18 | Benin | 34 | 4 | 13 | 1.1 | Africa |
19 | Bhutan | 23 | 0 | 0 | 0.4 | Asia |
20 | Bolivia | 167 | 41 | 8 | 3.8 | South America |
21 | Bosnia-Herzegovina | 76 | 173 | 8 | 4.6 | Europe |
22 | Botswana | 173 | 35 | 35 | 5.4 | Africa |
23 | Brazil | 245 | 145 | 16 | 7.2 | South America |
24 | Brunei | 31 | 2 | 1 | 0.6 | Asia |
25 | Bulgaria | 231 | 252 | 94 | 10.3 | Europe |
26 | Burkina Faso | 25 | 7 | 7 | 4.3 | Africa |
27 | Burundi | 88 | 0 | 0 | 6.3 | Africa |
28 | Cote d'Ivoire | 37 | 1 | 7 | 4.0 | Africa |
29 | Cabo Verde | 144 | 56 | 16 | 4.0 | Africa |
30 | Cambodia | 57 | 65 | 1 | 2.2 | Asia |
31 | Cameroon | 147 | 1 | 4 | 5.8 | Africa |
32 | Canada | 240 | 122 | 100 | 8.2 | North America |
33 | Central African Republic | 17 | 2 | 1 | 1.8 | Africa |
34 | Chad | 15 | 1 | 1 | 0.4 | Africa |
35 | Chile | 130 | 124 | 172 | 7.6 | South America |
36 | China | 79 | 192 | 8 | 5.0 | Asia |
37 | Colombia | 159 | 76 | 3 | 4.2 | South America |
38 | Comoros | 1 | 3 | 1 | 0.1 | Africa |
39 | Congo | 76 | 1 | 9 | 1.7 | Africa |
40 | Cook Islands | 0 | 254 | 74 | 5.9 | Oceania |
41 | Costa Rica | 149 | 87 | 11 | 4.4 | North America |
42 | Croatia | 230 | 87 | 254 | 10.2 | Europe |
43 | Cuba | 93 | 137 | 5 | 4.2 | North America |
44 | Cyprus | 192 | 154 | 113 | 8.2 | Europe |
45 | Czech Republic | 361 | 170 | 134 | 11.8 | Europe |
46 | North Korea | 0 | 0 | 0 | 0.0 | Asia |
47 | DR Congo | 32 | 3 | 1 | 2.3 | Africa |
48 | Denmark | 224 | 81 | 278 | 10.4 | Europe |
49 | Djibouti | 15 | 44 | 3 | 1.1 | Africa |
50 | Dominica | 52 | 286 | 26 | 6.6 | North America |
51 | Dominican Republic | 193 | 147 | 9 | 6.2 | North America |
52 | Ecuador | 162 | 74 | 3 | 4.2 | South America |
53 | Egypt | 6 | 4 | 1 | 0.2 | Africa |
54 | El Salvador | 52 | 69 | 2 | 2.2 | North America |
55 | Equatorial Guinea | 92 | 0 | 233 | 5.8 | Africa |
56 | Eritrea | 18 | 0 | 0 | 0.5 | Africa |
57 | Estonia | 224 | 194 | 59 | 9.5 | Europe |
58 | Ethiopia | 20 | 3 | 0 | 0.7 | Africa |
59 | Fiji | 77 | 35 | 1 | 2.0 | Oceania |
60 | Finland | 263 | 133 | 97 | 10.0 | Europe |
61 | France | 127 | 151 | 370 | 11.8 | Europe |
62 | Gabon | 347 | 98 | 59 | 8.9 | Africa |
63 | Gambia | 8 | 0 | 1 | 2.4 | Africa |
64 | Georgia | 52 | 100 | 149 | 5.4 | Europe |
65 | Germany | 346 | 117 | 175 | 11.3 | Europe |
66 | Ghana | 31 | 3 | 10 | 1.8 | Africa |
67 | Greece | 133 | 112 | 218 | 8.3 | Europe |
68 | Grenada | 199 | 438 | 28 | 11.9 | North America |
69 | Guatemala | 53 | 69 | 2 | 2.2 | North America |
70 | Guinea | 9 | 0 | 2 | 0.2 | Africa |
71 | Guinea-Bissau | 28 | 31 | 21 | 2.5 | Africa |
72 | Guyana | 93 | 302 | 1 | 7.1 | South America |
73 | Haiti | 1 | 326 | 1 | 5.9 | North America |
74 | Honduras | 69 | 98 | 2 | 3.0 | North America |
75 | Hungary | 234 | 215 | 185 | 11.3 | Europe |
76 | Iceland | 233 | 61 | 78 | 6.6 | Europe |
77 | India | 9 | 114 | 0 | 2.2 | Asia |
78 | Indonesia | 5 | 1 | 0 | 0.1 | Asia |
79 | Iran | 0 | 0 | 0 | 0.0 | Asia |
80 | Iraq | 9 | 3 | 0 | 0.2 | Asia |
81 | Ireland | 313 | 118 | 165 | 11.4 | Europe |
82 | Israel | 63 | 69 | 9 | 2.5 | Asia |
83 | Italy | 85 | 42 | 237 | 6.5 | Europe |
84 | Jamaica | 82 | 97 | 9 | 3.4 | North America |
85 | Japan | 77 | 202 | 16 | 7.0 | Asia |
86 | Jordan | 6 | 21 | 1 | 0.5 | Asia |
87 | Kazakhstan | 124 | 246 | 12 | 6.8 | Asia |
88 | Kenya | 58 | 22 | 2 | 1.8 | Africa |
89 | Kiribati | 21 | 34 | 1 | 1.0 | Oceania |
90 | Kuwait | 0 | 0 | 0 | 0.0 | Asia |
91 | Kyrgyzstan | 31 | 97 | 6 | 2.4 | Asia |
92 | Laos | 62 | 0 | 123 | 6.2 | Asia |
93 | Latvia | 281 | 216 | 62 | 10.5 | Europe |
94 | Lebanon | 20 | 55 | 31 | 1.9 | Asia |
95 | Lesotho | 82 | 29 | 0 | 2.8 | Africa |
96 | Liberia | 19 | 152 | 2 | 3.1 | Africa |
97 | Libya | 0 | 0 | 0 | 0.0 | Africa |
98 | Lithuania | 343 | 244 | 56 | 12.9 | Europe |
99 | Luxembourg | 236 | 133 | 271 | 11.4 | Europe |
100 | Madagascar | 26 | 15 | 4 | 0.8 | Africa |
101 | Malawi | 8 | 11 | 1 | 1.5 | Africa |
102 | Malaysia | 13 | 4 | 0 | 0.3 | Asia |
103 | Maldives | 0 | 0 | 0 | 0.0 | Asia |
104 | Mali | 5 | 1 | 1 | 0.6 | Africa |
105 | Malta | 149 | 100 | 120 | 6.6 | Europe |
106 | Marshall Islands | 0 | 0 | 0 | 0.0 | Oceania |
107 | Mauritania | 0 | 0 | 0 | 0.0 | Africa |
108 | Mauritius | 98 | 31 | 18 | 2.6 | Africa |
109 | Mexico | 238 | 68 | 5 | 5.5 | North America |
110 | Micronesia | 62 | 50 | 18 | 2.3 | Oceania |
111 | Monaco | 0 | 0 | 0 | 0.0 | Europe |
112 | Mongolia | 77 | 189 | 8 | 4.9 | Asia |
113 | Montenegro | 31 | 114 | 128 | 4.9 | Europe |
114 | Morocco | 12 | 6 | 10 | 0.5 | Africa |
115 | Mozambique | 47 | 18 | 5 | 1.3 | Africa |
116 | Myanmar | 5 | 1 | 0 | 0.1 | Asia |
117 | Namibia | 376 | 3 | 1 | 6.8 | Africa |
118 | Nauru | 49 | 0 | 8 | 1.0 | Oceania |
119 | Nepal | 5 | 6 | 0 | 0.2 | Asia |
120 | Netherlands | 251 | 88 | 190 | 9.4 | Europe |
121 | New Zealand | 203 | 79 | 175 | 9.3 | Oceania |
122 | Nicaragua | 78 | 118 | 1 | 3.5 | North America |
123 | Niger | 3 | 2 | 1 | 0.1 | Africa |
124 | Nigeria | 42 | 5 | 2 | 9.1 | Africa |
125 | Niue | 188 | 200 | 7 | 7.0 | Oceania |
126 | Norway | 169 | 71 | 129 | 6.7 | Europe |
127 | Oman | 22 | 16 | 1 | 0.7 | Asia |
128 | Pakistan | 0 | 0 | 0 | 0.0 | Asia |
129 | Palau | 306 | 63 | 23 | 6.9 | Oceania |
130 | Panama | 285 | 104 | 18 | 7.2 | North America |
131 | Papua New Guinea | 44 | 39 | 1 | 1.5 | Oceania |
132 | Paraguay | 213 | 117 | 74 | 7.3 | South America |
133 | Peru | 163 | 160 | 21 | 6.1 | South America |
134 | Philippines | 71 | 186 | 1 | 4.6 | Asia |
135 | Poland | 343 | 215 | 56 | 10.9 | Europe |
136 | Portugal | 194 | 67 | 339 | 11.0 | Europe |
137 | Qatar | 1 | 42 | 7 | 0.9 | Asia |
138 | South Korea | 140 | 16 | 9 | 9.8 | Asia |
139 | Moldova | 109 | 226 | 18 | 6.3 | Europe |
140 | Romania | 297 | 122 | 167 | 10.4 | Europe |
141 | Russian Federation | 247 | 326 | 73 | 11.5 | Asia |
142 | Rwanda | 43 | 2 | 0 | 6.8 | Africa |
143 | St. Kitts & Nevis | 194 | 205 | 32 | 7.7 | North America |
144 | St. Lucia | 171 | 315 | 71 | 10.1 | North America |
145 | St. Vincent & the Grenadines | 120 | 221 | 11 | 6.3 | North America |
146 | Samoa | 105 | 18 | 24 | 2.6 | Oceania |
147 | San Marino | 0 | 0 | 0 | 0.0 | Europe |
148 | Sao Tome & Principe | 56 | 38 | 140 | 4.2 | Africa |
149 | Saudi Arabia | 0 | 5 | 0 | 0.1 | Asia |
150 | Senegal | 9 | 1 | 7 | 0.3 | Africa |
151 | Serbia | 283 | 131 | 127 | 9.6 | Europe |
152 | Seychelles | 157 | 25 | 51 | 4.1 | Africa |
153 | Sierra Leone | 25 | 3 | 2 | 6.7 | Africa |
154 | Singapore | 60 | 12 | 11 | 1.5 | Asia |
155 | Slovakia | 196 | 293 | 116 | 11.4 | Europe |
156 | Slovenia | 270 | 51 | 276 | 10.6 | Europe |
157 | Solomon Islands | 56 | 11 | 1 | 1.2 | Oceania |
158 | Somalia | 0 | 0 | 0 | 0.0 | Africa |
159 | South Africa | 225 | 76 | 81 | 8.2 | Africa |
160 | Spain | 284 | 157 | 112 | 10.0 | Europe |
161 | Sri Lanka | 16 | 104 | 0 | 2.2 | Asia |
162 | Sudan | 8 | 13 | 0 | 1.7 | Africa |
163 | Suriname | 128 | 178 | 7 | 5.6 | South America |
164 | Swaziland | 90 | 2 | 2 | 4.7 | Africa |
165 | Sweden | 152 | 60 | 186 | 7.2 | Europe |
166 | Switzerland | 185 | 100 | 280 | 10.2 | Europe |
167 | Syria | 5 | 35 | 16 | 1.0 | Asia |
168 | Tajikistan | 2 | 15 | 0 | 0.3 | Asia |
169 | Thailand | 99 | 258 | 1 | 6.4 | Asia |
170 | Macedonia | 106 | 27 | 86 | 3.9 | Europe |
171 | Timor-Leste | 1 | 1 | 4 | 0.1 | Asia |
172 | Togo | 36 | 2 | 19 | 1.3 | Africa |
173 | Tonga | 36 | 21 | 5 | 1.1 | Oceania |
174 | Trinidad & Tobago | 197 | 156 | 7 | 6.4 | North America |
175 | Tunisia | 51 | 3 | 20 | 1.3 | Africa |
176 | Turkey | 51 | 22 | 7 | 1.4 | Asia |
177 | Turkmenistan | 19 | 71 | 32 | 2.2 | Asia |
178 | Tuvalu | 6 | 41 | 9 | 1.0 | Oceania |
179 | Uganda | 45 | 9 | 0 | 8.3 | Africa |
180 | Ukraine | 206 | 237 | 45 | 8.9 | Europe |
181 | United Arab Emirates | 16 | 135 | 5 | 2.8 | Asia |
182 | United Kingdom | 219 | 126 | 195 | 10.4 | Europe |
183 | Tanzania | 36 | 6 | 1 | 5.7 | Africa |
184 | USA | 249 | 158 | 84 | 8.7 | North America |
185 | Uruguay | 115 | 35 | 220 | 6.6 | South America |
186 | Uzbekistan | 25 | 101 | 8 | 2.4 | Asia |
187 | Vanuatu | 21 | 18 | 11 | 0.9 | Oceania |
188 | Venezuela | 333 | 100 | 3 | 7.7 | South America |
189 | Vietnam | 111 | 2 | 1 | 2.0 | Asia |
190 | Yemen | 6 | 0 | 0 | 0.1 | Asia |
191 | Zambia | 32 | 19 | 4 | 2.5 | Africa |
192 | Zimbabwe | 64 | 18 | 4 | 4.7 | Africa |
In [9]:
# reset back to normal
pd.reset_option('display.max_rows')
In [10]:
drinks
Out[10]:
country | beer_servings | spirit_servings | wine_servings | total_litres_of_pure_alcohol | continent | |
---|---|---|---|---|---|---|
0 | Afghanistan | 0 | 0 | 0 | 0.0 | Asia |
1 | Albania | 89 | 132 | 54 | 4.9 | Europe |
2 | Algeria | 25 | 0 | 14 | 0.7 | Africa |
3 | Andorra | 245 | 138 | 312 | 12.4 | Europe |
4 | Angola | 217 | 57 | 45 | 5.9 | Africa |
5 | Antigua & Barbuda | 102 | 128 | 45 | 4.9 | North America |
6 | Argentina | 193 | 25 | 221 | 8.3 | South America |
7 | Armenia | 21 | 179 | 11 | 3.8 | Europe |
8 | Australia | 261 | 72 | 212 | 10.4 | Oceania |
9 | Austria | 279 | 75 | 191 | 9.7 | Europe |
10 | Azerbaijan | 21 | 46 | 5 | 1.3 | Europe |
11 | Bahamas | 122 | 176 | 51 | 6.3 | North America |
12 | Bahrain | 42 | 63 | 7 | 2.0 | Asia |
13 | Bangladesh | 0 | 0 | 0 | 0.0 | Asia |
14 | Barbados | 143 | 173 | 36 | 6.3 | North America |
15 | Belarus | 142 | 373 | 42 | 14.4 | Europe |
16 | Belgium | 295 | 84 | 212 | 10.5 | Europe |
17 | Belize | 263 | 114 | 8 | 6.8 | North America |
18 | Benin | 34 | 4 | 13 | 1.1 | Africa |
19 | Bhutan | 23 | 0 | 0 | 0.4 | Asia |
20 | Bolivia | 167 | 41 | 8 | 3.8 | South America |
21 | Bosnia-Herzegovina | 76 | 173 | 8 | 4.6 | Europe |
22 | Botswana | 173 | 35 | 35 | 5.4 | Africa |
23 | Brazil | 245 | 145 | 16 | 7.2 | South America |
24 | Brunei | 31 | 2 | 1 | 0.6 | Asia |
25 | Bulgaria | 231 | 252 | 94 | 10.3 | Europe |
26 | Burkina Faso | 25 | 7 | 7 | 4.3 | Africa |
27 | Burundi | 88 | 0 | 0 | 6.3 | Africa |
28 | Cote d'Ivoire | 37 | 1 | 7 | 4.0 | Africa |
29 | Cabo Verde | 144 | 56 | 16 | 4.0 | Africa |
... | ... | ... | ... | ... | ... | ... |
163 | Suriname | 128 | 178 | 7 | 5.6 | South America |
164 | Swaziland | 90 | 2 | 2 | 4.7 | Africa |
165 | Sweden | 152 | 60 | 186 | 7.2 | Europe |
166 | Switzerland | 185 | 100 | 280 | 10.2 | Europe |
167 | Syria | 5 | 35 | 16 | 1.0 | Asia |
168 | Tajikistan | 2 | 15 | 0 | 0.3 | Asia |
169 | Thailand | 99 | 258 | 1 | 6.4 | Asia |
170 | Macedonia | 106 | 27 | 86 | 3.9 | Europe |
171 | Timor-Leste | 1 | 1 | 4 | 0.1 | Asia |
172 | Togo | 36 | 2 | 19 | 1.3 | Africa |
173 | Tonga | 36 | 21 | 5 | 1.1 | Oceania |
174 | Trinidad & Tobago | 197 | 156 | 7 | 6.4 | North America |
175 | Tunisia | 51 | 3 | 20 | 1.3 | Africa |
176 | Turkey | 51 | 22 | 7 | 1.4 | Asia |
177 | Turkmenistan | 19 | 71 | 32 | 2.2 | Asia |
178 | Tuvalu | 6 | 41 | 9 | 1.0 | Oceania |
179 | Uganda | 45 | 9 | 0 | 8.3 | Africa |
180 | Ukraine | 206 | 237 | 45 | 8.9 | Europe |
181 | United Arab Emirates | 16 | 135 | 5 | 2.8 | Asia |
182 | United Kingdom | 219 | 126 | 195 | 10.4 | Europe |
183 | Tanzania | 36 | 6 | 1 | 5.7 | Africa |
184 | USA | 249 | 158 | 84 | 8.7 | North America |
185 | Uruguay | 115 | 35 | 220 | 6.6 | South America |
186 | Uzbekistan | 25 | 101 | 8 | 2.4 | Asia |
187 | Vanuatu | 21 | 18 | 11 | 0.9 | Oceania |
188 | Venezuela | 333 | 100 | 3 | 7.7 | South America |
189 | Vietnam | 111 | 2 | 1 | 2.0 | Asia |
190 | Yemen | 6 | 0 | 0 | 0.1 | Asia |
191 | Zambia | 32 | 19 | 4 | 2.5 | Africa |
192 | Zimbabwe | 64 | 18 | 4 | 4.7 | Africa |
193 rows × 6 columns
COLUMNS
In [13]:
# the default for columns is 20
pd.get_option('display.max_columns')
Out[13]:
20
CELLS
In [ ]:
url = 'http://bit.ly/kaggletrain'
train = pd.read_csv(url)
train.head()
# in each cell, you can see '...'
# how do we change this?
In [15]:
pd.get_option('display.max_colwidth')
Out[15]:
50
In [16]:
# you can't use none here
pd.set_option('display.max_colwidth', 1000)
In [30]:
train.head()
Out[30]:
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22.0 | 1 | 0 | A/5 21171 | 7.250 | NaN | S |
1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Thayer) | female | 38.0 | 1 | 0 | PC 17599 | 71.283 | C85 | C |
2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.925 | NaN | S |
3 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35.0 | 1 | 0 | 113803 | 53.100 | C123 | S |
4 | 5 | 0 | 3 | Allen, Mr. William Henry | male | 35.0 | 0 | 0 | 373450 | 8.050 | NaN | S |
In [21]:
# decimal places for numbers
pd.get_option('display.precision')
Out[21]:
2
In [28]:
pd.set_option('display.precision', 3)
In [29]:
train.head()
Out[29]:
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22.0 | 1 | 0 | A/5 21171 | 7.250 | NaN | S |
1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Thayer) | female | 38.0 | 1 | 0 | PC 17599 | 71.283 | C85 | C |
2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.925 | NaN | S |
3 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35.0 | 1 | 0 | 113803 | 53.100 | C123 | S |
4 | 5 | 0 | 3 | Allen, Mr. William Henry | male | 35.0 | 0 | 0 | 373450 | 8.050 | NaN | S |
In [31]:
drinks.head()
Out[31]:
country | beer_servings | spirit_servings | wine_servings | total_litres_of_pure_alcohol | continent | |
---|---|---|---|---|---|---|
0 | Afghanistan | 0 | 0 | 0 | 0.0 | Asia |
1 | Albania | 89 | 132 | 54 | 4.9 | Europe |
2 | Algeria | 25 | 0 | 14 | 0.7 | Africa |
3 | Andorra | 245 | 138 | 312 | 12.4 | Europe |
4 | Angola | 217 | 57 | 45 | 5.9 | Africa |
In [32]:
drinks['x'] = drinks.wine_servings * 1000
In [33]:
drinks['y'] = drinks.total_litres_of_pure_alcohol * 1000
In [34]:
drinks.head()
Out[34]:
country | beer_servings | spirit_servings | wine_servings | total_litres_of_pure_alcohol | continent | x | y | |
---|---|---|---|---|---|---|---|---|
0 | Afghanistan | 0 | 0 | 0 | 0.0 | Asia | 0 | 0.0 |
1 | Albania | 89 | 132 | 54 | 4.9 | Europe | 54000 | 4900.0 |
2 | Algeria | 25 | 0 | 14 | 0.7 | Africa | 14000 | 700.0 |
3 | Andorra | 245 | 138 | 312 | 12.4 | Europe | 312000 | 12400.0 |
4 | Angola | 217 | 57 | 45 | 5.9 | Africa | 45000 | 5900.0 |
In [36]:
# split numbers using commas
pd.set_option('display.float_format', '{:,}'.format)
In [38]:
drinks.head()
Out[38]:
country | beer_servings | spirit_servings | wine_servings | total_litres_of_pure_alcohol | continent | x | y | |
---|---|---|---|---|---|---|---|---|
0 | Afghanistan | 0 | 0 | 0 | 0.0 | Asia | 0 | 0.0 |
1 | Albania | 89 | 132 | 54 | 4.9 | Europe | 54000 | 4,900.0 |
2 | Algeria | 25 | 0 | 14 | 0.7 | Africa | 14000 | 700.0 |
3 | Andorra | 245 | 138 | 312 | 12.4 | Europe | 312000 | 12,400.0 |
4 | Angola | 217 | 57 | 45 | 5.9 | Africa | 45000 | 5,900.0 |
In [40]:
drinks.dtypes
# this only affected y because x is int type
Out[40]:
country object beer_servings int64 spirit_servings int64 wine_servings int64 total_litres_of_pure_alcohol float64 continent object x int64 y float64 dtype: object
In [60]:
# we can convert y to float using .astype
# replace existing column using assignment
drinks['wine_servings'] = drinks.wine_servings.astype(float)
In [61]:
# we need to concatenate
drinks.dtypes
Out[61]:
country object beer_servings int64 spirit_servings int64 wine_servings float64 total_litres_of_pure_alcohol float64 continent object x int64 y float64 dtype: object
In [62]:
# run code again
drinks['x'] = drinks.wine_servings * 1000
In [64]:
drinks.head()
# it works now!
Out[64]:
country | beer_servings | spirit_servings | wine_servings | total_litres_of_pure_alcohol | continent | x | y | |
---|---|---|---|---|---|---|---|---|
0 | Afghanistan | 0 | 0 | 0.0 | 0.0 | Asia | 0.0 | 0.0 |
1 | Albania | 89 | 132 | 54.0 | 4.9 | Europe | 54,000.0 | 4,900.0 |
2 | Algeria | 25 | 0 | 14.0 | 0.7 | Africa | 14,000.0 | 700.0 |
3 | Andorra | 245 | 138 | 312.0 | 12.4 | Europe | 312,000.0 | 12,400.0 |
4 | Angola | 217 | 57 | 45.0 | 5.9 | Africa | 45,000.0 | 5,900.0 |
In [65]:
# offline documentation
pd.describe_option()
display.chop_threshold : float or None if set to a float value, all float values smaller then the given threshold will be displayed as exactly 0 by repr and friends. [default: None] [currently: None] display.colheader_justify : 'left'/'right' Controls the justification of column headers. used by DataFrameFormatter. [default: right] [currently: right] display.column_space No description available. [default: 12] [currently: 12] display.date_dayfirst : boolean When True, prints and parses dates with the day first, eg 20/01/2005 [default: False] [currently: False] display.date_yearfirst : boolean When True, prints and parses dates with the year first, eg 2005/01/20 [default: False] [currently: False] display.encoding : str/unicode Defaults to the detected encoding of the console. Specifies the encoding to be used for strings returned by to_string, these are generally strings meant to be displayed on the console. [default: UTF-8] [currently: UTF-8] display.expand_frame_repr : boolean Whether to print out the full DataFrame repr for wide DataFrames across multiple lines, `max_columns` is still respected, but the output will wrap-around across multiple "pages" if its width exceeds `display.width`. [default: True] [currently: True] display.float_format : callable The callable should accept a floating point number and return a string with the desired format of the number. This is used in some places like SeriesFormatter. See formats.format.EngFormatter for an example. [default: None] [currently: <built-in method format of str object at 0x11411fe68>] display.height : int Deprecated. [default: 60] [currently: 60] (Deprecated, use `display.max_rows` instead.) display.large_repr : 'truncate'/'info' For DataFrames exceeding max_rows/max_cols, the repr (and HTML repr) can show a truncated table (the default from 0.13), or switch to the view from df.info() (the behaviour in earlier versions of pandas). [default: truncate] [currently: truncate] display.latex.escape : bool This specifies if the to_latex method of a Dataframe uses escapes special characters. method. Valid values: False,True [default: True] [currently: True] display.latex.longtable :bool This specifies if the to_latex method of a Dataframe uses the longtable format. method. Valid values: False,True [default: False] [currently: False] display.latex.repr : boolean Whether to produce a latex DataFrame representation for jupyter environments that support it. (default: False) [default: False] [currently: False] display.line_width : int Deprecated. [default: 80] [currently: 80] (Deprecated, use `display.width` instead.) display.max_categories : int This sets the maximum number of categories pandas should output when printing out a `Categorical` or a Series of dtype "category". [default: 8] [currently: 8] display.max_columns : int If max_cols is exceeded, switch to truncate view. Depending on `large_repr`, objects are either centrally truncated or printed as a summary view. 'None' value means unlimited. In case python/IPython is running in a terminal and `large_repr` equals 'truncate' this can be set to 0 and pandas will auto-detect the width of the terminal and print a truncated object which fits the screen width. The IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to do correct auto-detection. [default: 20] [currently: 20] display.max_colwidth : int The maximum width in characters of a column in the repr of a pandas data structure. When the column overflows, a "..." placeholder is embedded in the output. [default: 50] [currently: 1000] display.max_info_columns : int max_info_columns is used in DataFrame.info method to decide if per column information will be printed. [default: 100] [currently: 100] display.max_info_rows : int or None df.info() will usually show null-counts for each column. For large frames this can be quite slow. max_info_rows and max_info_cols limit this null check only to frames with smaller dimensions than specified. [default: 1690785] [currently: 1690785] display.max_rows : int If max_rows is exceeded, switch to truncate view. Depending on `large_repr`, objects are either centrally truncated or printed as a summary view. 'None' value means unlimited. In case python/IPython is running in a terminal and `large_repr` equals 'truncate' this can be set to 0 and pandas will auto-detect the height of the terminal and print a truncated object which fits the screen height. The IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to do correct auto-detection. [default: 60] [currently: 60] display.max_seq_items : int or None when pretty-printing a long sequence, no more then `max_seq_items` will be printed. If items are omitted, they will be denoted by the addition of "..." to the resulting string. If set to None, the number of items to be printed is unlimited. [default: 100] [currently: 100] display.memory_usage : bool, string or None This specifies if the memory usage of a DataFrame should be displayed when df.info() is called. Valid values True,False,'deep' [default: True] [currently: True] display.mpl_style : bool Setting this to 'default' will modify the rcParams used by matplotlib to give plots a more pleasing visual style by default. Setting this to None/False restores the values to their initial value. [default: None] [currently: None] display.multi_sparse : boolean "sparsify" MultiIndex display (don't display repeated elements in outer levels within groups) [default: True] [currently: True] display.notebook_repr_html : boolean When True, IPython notebook will use html representation for pandas objects (if it is available). [default: True] [currently: True] display.pprint_nest_depth : int Controls the number of nested levels to process when pretty-printing [default: 3] [currently: 3] display.precision : int Floating point output precision (number of significant digits). This is only a suggestion [default: 6] [currently: 3] display.show_dimensions : boolean or 'truncate' Whether to print out dimensions at the end of DataFrame repr. If 'truncate' is specified, only print out the dimensions if the frame is truncated (e.g. not display all rows and/or columns) [default: truncate] [currently: truncate] display.unicode.ambiguous_as_wide : boolean Whether to use the Unicode East Asian Width to calculate the display text width. Enabling this may affect to the performance (default: False) [default: False] [currently: False] display.unicode.east_asian_width : boolean Whether to use the Unicode East Asian Width to calculate the display text width. Enabling this may affect to the performance (default: False) [default: False] [currently: False] display.width : int Width of the display in characters. In case python/IPython is running in a terminal this can be set to None and pandas will correctly auto-detect the width. Note that the IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to correctly detect the width. [default: 80] [currently: 80] io.excel.xls.writer : string The default Excel writer engine for 'xls' files. Available options: 'xlwt' (the default). [default: xlwt] [currently: xlwt] io.excel.xlsm.writer : string The default Excel writer engine for 'xlsm' files. Available options: 'openpyxl' (the default). [default: openpyxl] [currently: openpyxl] io.excel.xlsx.writer : string The default Excel writer engine for 'xlsx' files. Available options: 'xlsxwriter' (the default), 'openpyxl'. [default: xlsxwriter] [currently: xlsxwriter] io.hdf.default_format : format default format writing format, if None, then put will default to 'fixed' and append will default to 'table' [default: None] [currently: None] io.hdf.dropna_table : boolean drop ALL nan rows when appending to a table [default: False] [currently: False] mode.chained_assignment : string Raise an exception, warn, or no action if trying to use chained assignment, The default is warn [default: warn] [currently: warn] mode.sim_interactive : boolean Whether to simulate interactive mode for purposes of testing [default: False] [currently: False] mode.use_inf_as_null : boolean True means treat None, NaN, INF, -INF as null (old way), False means None and NaN are null, but INF, -INF are not null (new way). [default: False] [currently: False]
In [67]:
# specific searching
pd.describe_option('rows')
display.max_info_rows : int or None df.info() will usually show null-counts for each column. For large frames this can be quite slow. max_info_rows and max_info_cols limit this null check only to frames with smaller dimensions than specified. [default: 1690785] [currently: 1690785] display.max_rows : int If max_rows is exceeded, switch to truncate view. Depending on `large_repr`, objects are either centrally truncated or printed as a summary view. 'None' value means unlimited. In case python/IPython is running in a terminal and `large_repr` equals 'truncate' this can be set to 0 and pandas will auto-detect the height of the terminal and print a truncated object which fits the screen height. The IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to do correct auto-detection. [default: 60] [currently: 60]
In [69]:
# reset all options
pd.reset_option('all')
# do not worry about the warning
height has been deprecated. line_width has been deprecated, use display.width instead (currently both are identical)
/Users/ritchieng/anaconda3/envs/py3k/lib/python3.5/site-packages/ipykernel/__main__.py:2: FutureWarning: mpl_style had been deprecated and will be removed in a future version. Use `matplotlib.pyplot.style.use` instead. from ipykernel import kernelapp as app
Tags:
pandas