我的数据框如下所示:
df =
crashYear region OBJECTID
0 2000 Auckland Region 12285
1 2000 Bay of Plenty Region 1336
2 2000 Canterbury Region 3563
3 2000 Gisborne Region 319
4 2000 Hawke's Bay Region 1236
5 2000 Manawatū-Whanganui Region 1984
6 2000 Marlborough Region 272
7 2000 Nelson Region 288
8 2000 Northland Region 1015
9 2000 Otago Region 1553
10 2000 Southland Region 717
11 2000 Taranaki Region 761
12 2000 Tasman Region 296
13 2000 Waikato Region 2749
14 2000 Wellington Region 3197
15 2000 West Coast Region 294
16 2001 Auckland Region 13670
17 2001 Bay of Plenty Region 1741
18 2001 Canterbury Region 3884
19 2001 Gisborne Region 435
20 2001 Hawke's Bay Region 1318
21 2001 Manawatū-Whanganui Region 2038
22 2001 Marlborough Region 303
23 2001 Nelson Region 328
24 2001 Northland Region 1120
25 2001 Otago Region 1971
26 2001 Southland Region 928
27 2001 Taranaki Region 804
28 2001 Tasman Region 295
29 2001 Waikato Region 3638
30 2001 Wellington Region 3225
31 2001 West Coast Region 281
32 2002 Auckland Region 14811
33 2002 Bay of Plenty Region 1951
34 2002 Canterbury Region 3670
35 2002 Gisborne Region 450
36 2002 Hawke's Bay Region 1435
37 2002 Manawatū-Whanganui Region 2237
38 2002 Marlborough Region 387
39 2002 Nelson Region 391
40 2002 Northland Region 1236
41 2002 Otago Region 2257
42 2002 Southland Region 969
43 2002 Taranaki Region 839
44 2002 Tasman Region 321
45 2002 Waikato Region 3465
46 2002 Wellington Region 3218
47 2002 West Coast Region 270
48 2003 Auckland Region 14445
49 2003 Bay of Plenty Region 2267
50 2003 Canterbury Region 3548
51 2003 Gisborne Region 416
52 2003 Hawke's Bay Region 1565
53 2003 Manawatū-Whanganui Region 2067
54 2003 Marlborough Region 345
55 2003 Nelson Region 409
56 2003 Northland Region 1552
57 2003 Otago Region 2102
58 2003 Southland Region 950
59 2003 Taranaki Region 784
60 2003 Tasman Region 385
61 2003 Waikato Region 3652
62 2003 Wellington Region 3063
63 2003 West Coast Region 273
64 2004 Auckland Region 13426
65 2004 Bay of Plenty Region 2143
66 2004 Canterbury Region 3322
67 2004 Gisborne Region 450
68 2004 Hawke's Bay Region 1643
69 2004 Manawatū-Whanganui Region 1997
70 2004 Marlborough Region 378
71 2004 Nelson Region 427
72 2004 Northland Region 1540
73 2004 Otago Region 2190
74 2004 Southland Region 887
75 2004 Taranaki Region 755
76 2004 Tasman Region 349
77 2004 Waikato Region 3678
78 2004 Wellington Region 3374
79 2004 West Coast Region 350
80 2005 Auckland Region 13588
81 2005 Bay of Plenty Region 2281
82 2005 Canterbury Region 3722
83 2005 Gisborne Region 480
84 2005 Hawke's Bay Region 1730
85 2005 Manawatū-Whanganui Region 2087
86 2005 Marlborough Region 397
87 2005 Nelson Region 352
88 2005 Northland Region 1450
89 2005 Otago Region 2133
90 2005 Southland Region 955
91 2005 Taranaki Region 810
92 2005 Tasman Region 289
93 2005 Waikato Region 4170
94 2005 Wellington Region 3455
95 2005 West Coast Region 311
96 2006 Auckland Region 13763
97 2006 Bay of Plenty Region 2296
98 2006 Canterbury Region 4210
99 2006 Gisborne Region 446
100 2006 Hawke's Bay Region 1611
101 2006 Manawatū-Whanganui Region 2047
102 2006 Marlborough Region 412
103 2006 Nelson Region 410
104 2006 Northland Region 1543
105 2006 Otago Region 2145
106 2006 Southland Region 971
107 2006 Taranaki Region 841
108 2006 Tasman Region 310
109 2006 Waikato Region 4307
110 2006 Wellington Region 4037
111 2006 West Coast Region 321
112 2007 Auckland Region 13887
113 2007 Bay of Plenty Region 2314
114 2007 Canterbury Region 4542
115 2007 Gisborne Region 423
116 2007 Hawke's Bay Region 1844
117 2007 Manawatū-Whanganui Region 1972
118 2007 Marlborough Region 419
119 2007 Nelson Region 408
120 2007 Northland Region 1630
121 2007 Otago Region 2234
122 2007 Southland Region 978
123 2007 Taranaki Region 995
124 2007 Tasman Region 374
125 2007 Waikato Region 4282
126 2007 Wellington Region 4881
127 2007 West Coast Region 339
128 2008 Auckland Region 13548
129 2008 Bay of Plenty Region 2096
130 2008 Canterbury Region 4180
131 2008 Gisborne Region 503
132 2008 Hawke's Bay Region 1554
133 2008 Manawatū-Whanganui Region 1901
134 2008 Marlborough Region 387
135 2008 Nelson Region 417
136 2008 Northland Region 1560
137 2008 Otago Region 2195
138 2008 Southland Region 1020
139 2008 Taranaki Region 965
140 2008 Tasman Region 349
141 2008 Waikato Region 3909
142 2008 Wellington Region 4488
143 2008 West Coast Region 320
144 2009 Auckland Region 12866
145 2009 Bay of Plenty Region 2208
146 2009 Canterbury Region 3937
147 2009 Gisborne Region 519
148 2009 Hawke's Bay Region 1562
149 2009 Manawatū-Whanganui Region 1806
150 2009 Marlborough Region 376
151 2009 Nelson Region 422
152 2009 Northland Region 1550
153 2009 Otago Region 2204
154 2009 Southland Region 1069
155 2009 Taranaki Region 923
156 2009 Tasman Region 338
157 2009 Waikato Region 3826
158 2009 Wellington Region 4114
159 2009 West Coast Region 377
160 2010 Auckland Region 12753
161 2010 Bay of Plenty Region 2081
162 2010 Canterbury Region 3471
163 2010 Gisborne Region 506
164 2010 Hawke's Bay Region 1502
165 2010 Manawatū-Whanganui Region 2027
166 2010 Marlborough Region 354
167 2010 Nelson Region 394
168 2010 Northland Region 1441
169 2010 Otago Region 2046
170 2010 Southland Region 999
171 2010 Taranaki Region 856
172 2010 Tasman Region 297
173 2010 Waikato Region 3770
174 2010 Wellington Region 3827
175 2010 West Coast Region 357
176 2011 Auckland Region 11258
177 2011 Bay of Plenty Region 1942
178 2011 Canterbury Region 3266
179 2011 Gisborne Region 394
180 2011 Hawke's Bay Region 1249
181 2011 Manawatū-Whanganui Region 1917
182 2011 Marlborough Region 320
183 2011 Nelson Region 297
184 2011 Northland Region 1224
185 2011 Otago Region 1843
186 2011 Southland Region 816
187 2011 Taranaki Region 805
188 2011 Tasman Region 310
189 2011 Waikato Region 3548
190 2011 Wellington Region 2852
191 2011 West Coast Region 271
192 2012 Auckland Region 10865
193 2012 Bay of Plenty Region 1630
194 2012 Canterbury Region 3260
195 2012 Gisborne Region 347
196 2012 Hawke's Bay Region 1029
197 2012 Manawatū-Whanganui Region 1717
198 2012 Marlborough Region 293
199 2012 Nelson Region 295
200 2012 Northland Region 1216
201 2012 Otago Region 1689
202 2012 Southland Region 783
203 2012 Taranaki Region 716
204 2012 Tasman Region 263
205 2012 Waikato Region 3226
206 2012 Wellington Region 2731
207 2012 West Coast Region 264
208 2013 Auckland Region 10686
209 2013 Bay of Plenty Region 1633
210 2013 Canterbury Region 3306
211 2013 Gisborne Region 363
212 2013 Hawke's Bay Region 1045
213 2013 Manawatū-Whanganui Region 1644
214 2013 Marlborough Region 266
215 2013 Nelson Region 288
216 2013 Northland Region 1193
217 2013 Otago Region 1609
218 2013 Southland Region 756
219 2013 Taranaki Region 670
220 2013 Tasman Region 290
221 2013 Waikato Region 3041
222 2013 Wellington Region 2968
223 2013 West Coast Region 256
224 2014 Auckland Region 10640
225 2014 Bay of Plenty Region 1564
226 2014 Canterbury Region 3350
227 2014 Gisborne Region 295
228 2014 Hawke's Bay Region 998
229 2014 Manawatū-Whanganui Region 1671
230 2014 Marlborough Region 282
231 2014 Nelson Region 273
232 2014 Northland Region 1265
233 2014 Otago Region 1570
234 2014 Southland Region 817
235 2014 Taranaki Region 602
236 2014 Tasman Region 213
237 2014 Waikato Region 3134
238 2014 Wellington Region 2745
239 2014 West Coast Region 264
240 2015 Auckland Region 11442
241 2015 Bay of Plenty Region 1799
242 2015 Canterbury Region 3255
243 2015 Gisborne Region 284
244 2015 Hawke's Bay Region 1002
245 2015 Manawatū-Whanganui Region 1828
246 2015 Marlborough Region 317
247 2015 Nelson Region 281
248 2015 Northland Region 1366
249 2015 Otago Region 1855
250 2015 Southland Region 861
251 2015 Taranaki Region 675
252 2015 Tasman Region 259
253 2015 Waikato Region 3549
254 2015 Wellington Region 2919
255 2015 West Coast Region 311
256 2016 Auckland Region 13308
257 2016 Bay of Plenty Region 2267
258 2016 Canterbury Region 3624
259 2016 Gisborne Region 362
260 2016 Hawke's Bay Region 1340
261 2016 Manawatū-Whanganui Region 1900
262 2016 Marlborough Region 417
263 2016 Nelson Region 348
264 2016 Northland Region 1501
265 2016 Otago Region 2018
266 2016 Southland Region 941
267 2016 Taranaki Region 742
268 2016 Tasman Region 359
269 2016 Waikato Region 3989
270 2016 Wellington Region 3617
271 2016 West Coast Region 369
272 2017 Auckland Region 13786
273 2017 Bay of Plenty Region 2296
274 2017 Canterbury Region 3660
275 2017 Gisborne Region 387
276 2017 Hawke's Bay Region 1388
277 2017 Manawatū-Whanganui Region 2188
278 2017 Marlborough Region 431
279 2017 Nelson Region 350
280 2017 Northland Region 1670
281 2017 Otago Region 1927
282 2017 Southland Region 814
283 2017 Taranaki Region 779
284 2017 Tasman Region 449
285 2017 Waikato Region 4688
286 2017 Wellington Region 3957
287 2017 West Coast Region 409
288 2018 Auckland Region 12631
289 2018 Bay of Plenty Region 2366
290 2018 Canterbury Region 3551
291 2018 Gisborne Region 485
292 2018 Hawke's Bay Region 1478
293 2018 Manawatū-Whanganui Region 2210
294 2018 Marlborough Region 442
295 2018 Nelson Region 366
296 2018 Northland Region 1841
297 2018 Otago Region 1979
298 2018 Southland Region 821
299 2018 Taranaki Region 839
300 2018 Tasman Region 390
301 2018 Waikato Region 4692
302 2018 Wellington Region 3835
303 2018 West Coast Region 376
304 2019 Auckland Region 11786
305 2019 Bay of Plenty Region 2445
306 2019 Canterbury Region 3275
307 2019 Gisborne Region 466
308 2019 Hawke's Bay Region 1465
309 2019 Manawatū-Whanganui Region 2208
310 2019 Marlborough Region 450
311 2019 Nelson Region 379
312 2019 Northland Region 1670
313 2019 Otago Region 2039
314 2019 Southland Region 864
315 2019 Taranaki Region 844
316 2019 Tasman Region 375
317 2019 Waikato Region 4477
318 2019 Wellington Region 3655
319 2019 West Coast Region 380
320 2020 Auckland Region 9337
321 2020 Bay of Plenty Region 2037
322 2020 Canterbury Region 3020
323 2020 Gisborne Region 482
324 2020 Hawke's Bay Region 1376
325 2020 Manawatū-Whanganui Region 2065
326 2020 Marlborough Region 341
327 2020 Nelson Region 318
328 2020 Northland Region 1477
329 2020 Otago Region 1654
330 2020 Southland Region 751
331 2020 Taranaki Region 795
332 2020 Tasman Region 331
333 2020 Waikato Region 3746
334 2020 Wellington Region 3042
335 2020 West Coast Region 291
336 2021 Auckland Region 1461
337 2021 Bay of Plenty Region 365
338 2021 Canterbury Region 511
339 2021 Gisborne Region 66
340 2021 Hawke's Bay Region 216
341 2021 Manawatū-Whanganui Region 362
342 2021 Marlborough Region 44
343 2021 Nelson Region 54
344 2021 Northland Region 239
345 2021 Otago Region 245
346 2021 Southland Region 120
347 2021 Taranaki Region 118
348 2021 Tasman Region 62
349 2021 Waikato Region 663
350 2021 Wellington Region 447
351 2021 West Coast Region 47
我想使用seaborn catplot 绘制条形图,并希望以4 x 4 矩阵显示区域数据。以下是我的代码:
import seaborn as sns
sns.catplot(data=df,kind='bar',y='OBJECTID',x='crashYear',col_wrap=4)
当我运行上面的代码时,它显示以下错误:
ValueError: Number of rows must be a positive integer, not 0
我不知道我在哪里犯了错误。有人可以帮我解决这个问题吗?
最佳答案
您忘记了 col='region'
参数:
import seaborn as sns
sns.catplot(data=df, kind='bar', y='OBJECTID', x='crashYear', col='region', col_wrap=4)
输出:
关于python - Seaborn Catplot : Number of rows must be a positive integer, 不是 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69832744/