如何解决如何绘制一年中污染报告的数量
data2=pd.read_csv('Data gathered.csv',parse_dates=["DATE"])
data2['DATE'].plot()
fig,ax = plt.subplots(figsize=(12,5))
ax.plot(data2['DATE'],data2.index)
我想绘制一个时间序列,其中显示一年中发生了多少报告。当我执行上面的代码时,它给了我每个报告年份的索引数 我真的不知道在我的 x 轴上放什么。
解决方法
- 使用
$ export OS_USERNAME=admin $ export OS_PASSWORD=ADMIN_PASS $ export OS_PROJECT_NAME=admin $ export OS_USER_DOMAIN_NAME=Default $ export OS_PROJECT_DOMAIN_NAME=Default $ export OS_AUTH_URL=http://controller:5000/v3 $ export OS_IDENTITY_API_VERSION=3
访问器datetime
提取.dt
,然后使用year
绘制pandas.DataFrame.plot
。
.value_counts()
,
你所说的报告是什么意思有点不清楚,但我认为你的 df 中的每一行都是一份报告。另外,你说你想要按年报告的数量,所以我会建议以下。通过这样做从 DATE
中提取年份,并创建一个虚拟变量:
data2['Date_date'] = pd.to_datetime(data2['DATE'])
data2['Year'] =data2['Date_date'].dt.year
data2['dummy'] = 1
print(data2)
返回:
COUNTY Division FILE NAME \
0 HIDALGO REM/VCIOP MCDONALDS 42-1615
1 HIDALGO REM/DCRP PRIDE'S CLEANERS
2 HIDALGO REM/PST STRIPES 9625
3 HIDALGO REM/PST 7-ELEVEN STORE 36529
4 HIDALGO REM/PST 7-ELEVEN STORE 40672
5 HIDALGO REM/PST ECONOMY DRIVE INN FFP 290
6 HIDALGO REM/PST FFP 297 FORMER ECONOMY DRIVE IN 114691
7 HIDALGO REM/PST FORMER GINOS MEAT MARKET
8 HIDALGO REM/PST HOP SHOP 1
9 HIDALGO REM/PST SAN JUANITA TREVINO PROPERTY
10 HIDALGO REM/PST STRIPES 9634
11 HIDALGO REM/PST STRIPES 9646
12 HIDALGO REM/PST STRIPES 9673
13 HIDALGO REM/PST SUNRISE 1
14 HIDALGO REM/PST TEXACO
15 HIDALGO REM/PST AZIZ CONVENIENCE STORE 16
16 HIDALGO REM/PST AZIZ CONVENIENCE STORE 8
17 HIDALGO REM/PST JRS XPRESS
18 HIDALGO REM/PST SUPER OXXO STATION
19 HIDALGO REM/VCP ADOBE REFINERY
20 HIDALGO REM/VCP AGRILIANCE EDINBURG FACILITY
21 HIDALGO REM/VCP 200 WEST RAILROAD STREET
22 HIDALGO REM/CA WAL-MART STORE 93549
23 HIDALGO REM/PST 23RD STREET GW PLUME
24 HIDALGO REM/PST BEST PIC CONVENIENCE STORE
25 HIDALGO REM/PST ECONOMY FOOD N GAS STORE 53
26 HIDALGO REM/PST HERNANDEZ FOOD MART
27 HIDALGO REM/PST HOP N SHOP 5 (TORTILLERIA RUIZ)
28 HIDALGO REM/PST QUICK PIC 4
29 HIDALGO REM/PST QUICK PIC COUNTRY STOP
30 HIDALGO REM/VCP ANGLO IRON AND METAL MCALLEN
31 HIDALGO WPD/MSW C & T LANDFILL (PRE-SUBTITLE D AND SUBTITLE D)
32 HIDALGO WPD/MSW CITY OF EDINBURG LANDFILL (PRE-
33 HIDALGO REM/VCP CROP PRODUCTION SERVICES
34 HIDALGO O&G EAST MCCOOK CENTRAL FACILITY,PIT\nPERMIT
35 HIDALGO O&G FORMER SHELL GAS WELL (1401 N. 16TH ST. MCALLEN)
36 HIDALGO O&G GANAWAY FACILITY
37 HIDALGO O&G HAMMAN COMPRESSOR STATION
38 HIDALGO O&G MCALLEN RANCH
39 HIDALGO O&G MONTE CHRISTO FI JOHNSON
40 HIDALGO O&G SHELL MCALLEN STATION (FORMER\nCOASTAL STATES ...
File Number LOCATION LATITUDE \
0 1087 3318 US BUSINESS HWY 83,WESLACO 26.152818
1 DC0025 2204 WEST NOLANA,MCALLEN 26.241222
2 120410 721 N MCCOLL RD,MCALLEN 26.208402
3 120290 822 W US HIGHWAY 83,SAN JUAN 26.191568
4 120511 6400 S 23RD ST,MCALLEN 26.150070
5 116761 2015 S MCCOLL RD,EDINBURG 26.286891
6 NaN 1525 N TEXAS BLVD,WESLACO 26.176380
7 120247 700 W STATE AVE,PHARR 26.197261
8 113110 1417 N CONWAY AVE,MISSION 26.220368
9 120715 723 E UNIVERSITY DR,EDINBURG 26.300645
10 119665 602 W 2ND ST,MERCEDES 26.149780
11 120448 1601 N 10TH ST,MCALLEN 26.218037
12 120419 621 E NOLANA AVE,MCALLEN 26.237706
13 103228 FM 1015,WESLACO 26.227820
14 98334 1701 S 10TH ST,MCALLEN 26.188762
15 119730 3000 N WARE RD,MCALLEN 26.235534
16 119727 2831 W US HIGHWAY 83,MCALLEN 26.207001
17 120629 3704 N RAUL LONGORIA RD,SAN JUAN 26.229621
18 115176 FM 1015,PROGRESO 26.090420
19 1657 ABANDONED REFINERY NO ADDRESS 0.5 MILES NORTH ... 26.298628
20 2417 501 E MONTE CRISTO RD,EDINBURG 26.337000
21 2304 200 W RAILRD ST,WESLACO 26.160388
22 T2055 NORTHWEST CORNER OF TRENTON &FM 2061 A MCCOLL ... 26.267752
23 117954 23RD ST,MCALLEN 26.213500
24 119278 1701 E MILE 5 N,WESLACO 26.126750
25 119012 601 S CLOSNER BLVD,EDINBURG 26.296313
26 117177 502 S SAN ANTONIO AVE,SAN JUAN 26.190150
27 118036 400 S CAGE BLVD,PHARR 26.191329
28 111723 2002 W HWY 83,MERCEDES 26.187778
29 115600 11110 MILE 2 E,MERCEDES 26.187778
30 196 2 S 21ST ST,MCALLEN 26.202780
31 MSW00151A S SIDE OF FM 1017,4.0 MI W OF INT US 281 AND ... 26.580000
32 MSW00956C 900 E ENCINITOS RD EDINBURG 26.395000
33 2313 WESLACO CITY BUSINESS 83 MILANO RD 3KM EAST OF... 26.165519
34 OCP#5026 SHELL EXPLORATION AND PRODUCTION\nCO. 26.468900
35 OCP#5159 SHELL EXPLORATION AND PRODUCTION COMPANY 26.217700
36 OCP#5008 MO-VAC SERVICE CO.,INC. 26.383900
37 OCP#5045 HILCORP ENERGY COMPANY (FORMERLY NEWFIELD EXPL... 26.446800
38 OCP#2613 HILCORP (FORMERLY FOREST OIL\nPRODUCTION) 26.602200
39 OCP#4286 HILCORP ENERGY COMPANY (FORMERLY NEWFIELD EXPL... 26.463000
40 OCP#1837 KINDERMORGAN (FORMERLY EL PASO MERCHANT ENERGY... 26.621700
LONGITUDE CONTAMINANTS DATE \
0 -97.956884 PAH 2018-03-20
1 -98.237745 CHLORINATED SOLVENTS 2005-04-29
2 -98.211955 DIESEL,GASOLINE 2017-12-11
3 -98.167134 GASOLINE 2016-08-22
4 -98.254685 GASOLINE 2018-03-07
5 -98.198046 GASOLINE 2005-10-13
6 -97.991150 GASOLINE 1999-07-09
7 -98.191799 GASOLINE 2017-04-24
8 -98.325309 GASOLINE 1998-03-25
9 -98.154873 GASOLINE 2017-11-18
10 -97.916083 GASOLINE 2014-12-13
11 -98.227928 GASOLINE 2017-10-20
12 -98.206965 GASOLINE 2017-11-03
13 -97.959880 GASOLINE 1992-06-03
14 -98.232189 GASOLINE 1991-03-22
15 -98.256408 GASOLINE,DIESEL 2015-06-29
16 -98.253249 GASOLINE,DIESEL 2015-06-29
17 -98.148887 GASOLINE,DIESEL 2018-10-16
18 -97.958640 GASOLINE,DIESEL 2001-05-02
19 -98.035970 METALS,CHLORINATED SOLVENTS 2003-12-08
20 -98.150698 OTHER 2011-07-15
21 -97.991605 PESTICIDES,HERBICIDES 2010-03-26
22 -98.204565 SVOCS 2005-11-18
23 -98.237100 UNKNOWN 1989-07-18
24 -97.973770 UNKNOWN 2013-10-14
25 -98.163493 UNKNOWN 2012-08-14
26 -98.160190 UNKNOWN 2006-09-29
27 -98.184896 UNKNOWN 2009-03-03
28 -97.878158 UNKNOWN 1996-10-08
29 -97.878158 UNKNOWN 2002-10-08
30 -98.237780 VOCS 1996-03-07
31 -98.180000 VOCS (1,1-DCA; CIS-1,2-DCE; DICHLORODIFLUOROME... 1995-02-13
32 -98.131600 VOCS (1,2-DCA; CIS-1,2-DCE) 2012-07-25
33 -98.017608 VOCS,PESTICIDES,METALS,SVOCS,PCBS 2010-05-06
34 -98.381000 TPH,BTEX NaN
35 -98.235100 CHLORIDE,TDS,AS NaN
36 -98.297300 CHLORIDE NaN
37 -98.289200 TPH,BTEX,PSH NaN
38 -98.265800 BENZENE,OTHER METALS NaN
39 -98.319000 TPH,BENZENE,PSH,CHLORIDE NaN
40 -98.316900 TPH,PSH NaN
ENF-STATUS ACT-STATUS 5.236 Category Date_date \
0 NaN 0 Other Business Establishments 2018-03-20
1 5B 0 Dry cleaning 2005-04-29
2 2 2A Gas Station 2017-12-11
3 2 2A Supermarket/Convenience stores 2016-08-22
4 2 6 Supermarket/Convenience stores 2018-03-07
5 1B 1A Other Business Establishments 2005-10-13
6 5B 6 Supermarket/Convenience stores 1999-07-09
7 2 6 Supermarket/Convenience stores 2017-04-24
8 2 6 Supermarket/Convenience stores 1998-03-25
9 2 6 Other Business Establishments 2017-11-18
10 2 2A Gas Station 2014-12-13
11 2 2A Gas Station 2017-10-20
12 1B 1A Gas Station 2017-11-03
13 2 2A Gas Station 1992-06-03
14 5B 4 Gas Station 1991-03-22
15 2 6 Gas Station 2015-06-29
16 2 6 Gas Station 2015-06-29
17 2 6 Supermarket/Convenience stores 2018-10-16
18 2 2A Supermarket/Convenience stores 2001-05-02
19 0B 5 Oil wells/Refinaries 2003-12-08
20 0B 2A Industrial/Agricutural factory 2011-07-15
21 0B 2A Unknown 2010-03-26
22 0A 0 Supermarket/Convenience stores 2005-11-18
23 5B 2A Gas Station 1989-07-18
24 2 2A Supermarket/Convenience stores 2013-10-14
25 1B 1A Gas Station 2012-08-14
26 5B 2A Supermarket/Convenience stores 2006-09-29
27 1B 1A Supermarket/Convenience stores 2009-03-03
28 2 2A Supermarket/Convenience stores 1996-10-08
29 1B 1A Supermarket/Convenience stores 2002-10-08
30 0B 5 Industrial/Agricutural factory 1996-03-07
31 2B 4,5A Landfills 1995-02-13
32 2B 2B Landfills 2012-07-25
33 0B 5 Industrial/Agricutural factory 2010-05-06
34 0 3 Industrial/Agricutural factory NaT
35 0 6C Oil wells/Refinaries NaT
36 2 2A Industrial/Agricutural factory NaT
37 0 4 Oil wells/Refinaries NaT
38 0 4 Oil wells/Refinaries NaT
39 0 4 Oil wells/Refinaries NaT
40 0 4 Oil wells/Refinaries NaT
Year dummy
0 2018.0 1
1 2005.0 1
2 2017.0 1
3 2016.0 1
4 2018.0 1
5 2005.0 1
6 1999.0 1
7 2017.0 1
8 1998.0 1
9 2017.0 1
10 2014.0 1
11 2017.0 1
12 2017.0 1
13 1992.0 1
14 1991.0 1
15 2015.0 1
16 2015.0 1
17 2018.0 1
18 2001.0 1
19 2003.0 1
20 2011.0 1
21 2010.0 1
22 2005.0 1
23 1989.0 1
24 2013.0 1
25 2012.0 1
26 2006.0 1
27 2009.0 1
28 1996.0 1
29 2002.0 1
30 1996.0 1
31 1995.0 1
32 2012.0 1
33 2010.0 1
34 NaN 1
35 NaN 1
36 NaN 1
37 NaN 1
38 NaN 1
39 NaN 1
40 NaN 1
然后,按年份对数据框进行分组:
df = data2.groupby('Year').count()
df = df.reset_index()
print(df[['Year','dummy']])
哪个返回
Year dummy
0 1989.0 1
1 1991.0 1
2 1992.0 1
3 1995.0 1
4 1996.0 2
5 1998.0 1
6 1999.0 1
7 2001.0 1
8 2002.0 1
9 2003.0 1
10 2005.0 3
11 2006.0 1
12 2009.0 1
13 2010.0 2
14 2011.0 1
15 2012.0 2
16 2013.0 1
17 2014.0 1
18 2015.0 2
19 2016.0 1
20 2017.0 5
21 2018.0 3
然后绘制
lines = df.plot.line(x='Year',y='dummy')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。