av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Python 數(shù)據(jù)的累加與統(tǒng)計(jì)的示例代碼

瀏覽:35日期:2022-07-15 11:55:35

問題

你需要處理一個(gè)很大的數(shù)據(jù)集并需要計(jì)算數(shù)據(jù)總和或其他統(tǒng)計(jì)量。

解決方案

對(duì)于任何涉及到統(tǒng)計(jì)、時(shí)間序列以及其他相關(guān)技術(shù)的數(shù)據(jù)分析問題,都可以考慮使用 Pandas庫 。

為了讓你先體驗(yàn)下,下面是一個(gè)使用Pandas來分析芝加哥城市的 老鼠和嚙齒類動(dòng)物數(shù)據(jù)庫 的例子。 在我寫這篇文章的時(shí)候,這個(gè)數(shù)據(jù)庫是一個(gè)擁有大概74,000行數(shù)據(jù)的CSV文件。

>>> import pandas>>> # Read a CSV file, skipping last line>>> rats = pandas.read_csv(’rats.csv’, skip_footer=1)>>> rats<class ’pandas.core.frame.DataFrame’>Int64Index: 74055 entries, 0 to 74054Data columns:Creation Date 74055 non-null valuesStatus 74055 non-null valuesCompletion Date 72154 non-null valuesService Request Number 74055 non-null valuesType of Service Request 74055 non-null valuesNumber of Premises Baited 65804 non-null valuesNumber of Premises with Garbage 65600 non-null valuesNumber of Premises with Rats 65752 non-null valuesCurrent Activity 66041 non-null valuesMost Recent Action 66023 non-null valuesStreet Address 74055 non-null valuesZIP Code 73584 non-null valuesX Coordinate 74043 non-null valuesY Coordinate 74043 non-null valuesWard 74044 non-null valuesPolice District 74044 non-null valuesCommunity Area 74044 non-null valuesLatitude 74043 non-null valuesLongitude 74043 non-null valuesLocation 74043 non-null valuesdtypes: float64(11), object(9)>>> # Investigate range of values for a certain field>>> rats[’Current Activity’].unique()array([nan, Dispatch Crew, Request Sanitation Inspector], dtype=object)>>> # Filter the data>>> crew_dispatched = rats[rats[’Current Activity’] == ’Dispatch Crew’]>>> len(crew_dispatched)65676>>>>>> # Find 10 most rat-infested ZIP codes in Chicago>>> crew_dispatched[’ZIP Code’].value_counts()[:10]60647 383760618 353060614 328460629 325160636 280160657 246560641 223860609 220660651 215260632 2071>>>>>> # Group by completion date>>> dates = crew_dispatched.groupby(’Completion Date’)<pandas.core.groupby.DataFrameGroupBy object at 0x10d0a2a10>>>> len(dates)472>>>>>> # Determine counts on each day>>> date_counts = dates.size()>>> date_counts[0:10]Completion Date01/03/2011 401/03/2012 12501/04/2011 5401/04/2012 3801/05/2011 7801/05/2012 10001/06/2011 10001/06/2012 5801/07/2011 101/09/2012 12>>>>>> # Sort the counts>>> date_counts.sort()>>> date_counts[-10:]Completion Date10/12/2012 31310/21/2011 31409/20/2011 31610/26/2011 31902/22/2011 32510/26/2012 33303/17/2011 33610/13/2011 37810/14/2011 39110/07/2011 457>>>

嗯,看樣子2011年10月7日對(duì)老鼠們來說是個(gè)很忙碌的日子啊!^_^

討論

Pandas是一個(gè)擁有很多特性的大型函數(shù)庫,我在這里不可能介紹完。 但是只要你需要去分析大型數(shù)據(jù)集合、對(duì)數(shù)據(jù)分組、計(jì)算各種統(tǒng)計(jì)量或其他類似任務(wù)的話,這個(gè)函數(shù)庫真的值得你去看一看。

以上就是Python 數(shù)據(jù)的累加與統(tǒng)計(jì)的方法的詳細(xì)內(nèi)容,更多關(guān)于Python 數(shù)據(jù)的累加與統(tǒng)計(jì)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 美女逼网站 | 亚洲狠狠 | 日本a在线 | 黄色毛片黄色毛片 | 亚洲精品一区二区三区蜜桃久 | 亚洲狠狠爱一区二区三区 | 国产精品久久网 | 一级做受毛片免费大片 | 女人一区 | 亚洲成人免费视频在线 | 亚洲成人福利视频 | 国产xxxx岁13xxxxhd | 久久网站黄 | 久久国品片| 日韩国产精品一区二区三区 | 亚洲国产精品一区二区www | 国产精品成人一区二区 | 国产精品久久亚洲 | 免费黄色在线观看 | 成人在线免费观看av | 一区二区在线免费观看视频 | 玖玖在线免费视频 | 欧美狠狠操 | 亚洲精品99 | 天堂亚洲| 一级片免费观看 | 91精品久久久久久久久中文字幕 | 国产福利资源在线 | 91资源在线| 亚洲精品一区中文字幕乱码 | 国产精品欧美大片 | 日韩在线中文 | 在线观看国产视频 | 成人免费视频网站在线观看 | 亚洲一区二区三区免费在线观看 | 亚洲精品国产电影 | 91精品国产色综合久久 | 日韩精品一区二区三区中文在线 | 欧美久久久久久久久 | 亚洲精品乱码久久久久久9色 | 真人一级毛片 |