数据分析包Panda学习笔记(二)

3.1 Series.str 包含的常用方法

startwith
endwith
contains
upper
lower
find #找第一个目标字符串出现的下标
split
strip #去空格
replace
slice(0,12)#切片
match#正则匹配
extract#提取正则中的组到每一列
df.City = df.City.str.strip() #去空格,格式化数据
df.City
0            Basildon
1           Parkville
2             Astoria
3              Echuca
4      Cahaba Heights
5           Mickleton
6              Peoria
7              Martin
8            Tel Aviv
9              Chatou
10           New York
11          Eindhoven
12       Shavano Park
13              Eagle
14          Riverside
15        Julianstown
16             Ottawa
17          Hyderabad
18             London
19     Salt Lake City
20         Manchester
21          Ballynora
22         Roodepoort
23        Chula Vista
24             Kuopio
25         Sugar Land
26           New York
27             London
28             Morton
29          Los Gatos
            ...      
968             Perth
969        Greenville
970      Pls Vrds Est
971    Hradec Kralove
972         Maidstone
973      Saint Albans
974         Voluntari
975             Nadur
976          Morrison
977            Cobham
978             Izmir
979         Hollywood
980          Brighton
981            Hawera
982         Worongary
983         Atlantida
984       El Escorial
985          Morrison
986           Augusta
987            Avalon
988            Sydney
989             Lahti
990        Inner City
991             Baden
992      Huddersfield
993           Belfast
994       Black River
995       Skaneateles
996         Haverhill
997           Madison
Name: City, Length: 998, dtype: object
import locale

#将Price去逗号,再转为int形式
df.Price = df.Price.str.replace(',','')

df.Price = df.Price.apply(locate.atoi) #df.apply() 对每一行都运行参数
# order by 排序
df.sort_values('Price',ascending=False)
Transaction_date Product Price Payment_Type Name City State Country Account_Created Last_Login Latitude Longitude Price2
477 1/30/09 7:42 Product1 250 Visa Tabatha Altadena CA United States 12/28/08 14:42 2002/3/9 18:09 34.189720 -118.130280 250
294 1/21/09 11:28 Product1 800 Amex Heloise Arlington VA United States 9/25/05 20:26 1/26/09 6:23 38.890280 -77.084440 800
0 2001/2/9 6:17 Product1 1200 Mastercard carolina Basildon England United Kingdom 2001/2/9 6:00 2001/2/9 6:08 51.500000 -1.116667 1200
627 2001/8/9 12:46 Product1 1200 Mastercard Trine Marie Orillia Ontario Canada 12/16/08 22:57 2002/10/9 22:11 44.600000 -79.416667 1200
628 1/29/09 16:07 Product1 1200 Diners Kim Paris Ile-de-France France 1/29/09 15:45 2002/10/9 22:24 48.866667 2.333333 1200
629 1/29/09 13:41 Product1 1200 Visa John San Jose CA United States 1/14/04 21:59 2002/10/9 23:58 37.339440 -121.893890 1200
630 2001/8/9 6:29 Product1 1200 Visa Rich Ingelheim-Mitte Rhineland-Palatinate Germany 3/24/06 6:21 2002/10/9 23:59 49.983333 8.066667 1200
631 2001/4/9 12:53 Product1 1200 Diners Kayla Leamington Spa England United Kingdom 2012/11/8 7:35 2002/11/9 0:04 52.300000 -1.533333 1200
632 1/14/09 12:55 Product1 1200 Visa Richard and Comfort Regensdorf Zurich Switzerland 2001/11/9 10:36 2002/11/9 1:58 47.433333 8.466667 1200
633 1/14/09 6:35 Product1 1200 Visa Eric Melbourne Victoria Australia 7/25/08 7:02 2002/11/9 2:05 -37.816667 144.966667 1200
634 1/27/09 13:08 Product1 1200 Mastercard Melissa Geneve Geneve Switzerland 2005/9/8 8:50 2002/11/9 2:19 46.200000 6.166667 1200
635 1/31/09 23:09 Product1 1200 Diners Dawn Vaucluse New South Wales Australia 9/13/04 22:55 2002/11/9 3:09 -33.866667 151.283333 1200
636 1/21/09 14:34 Product1 1200 Mastercard Tamara Klosterneuburg Lower Austria Austria 1/21/09 14:12 2002/11/9 3:19 48.300000 16.316667 1200
637 1/16/09 8:28 Product1 1200 Visa Ashley Rancho Cordova CA United States 2001/9/9 12:13 2002/11/9 8:34 38.589170 -121.301670 1200
638 2001/11/9 9:55 Product1 1200 Visa familly Creemore Ontario Canada 2001/10/9 7:14 2002/11/9 8:45 44.316667 -80.100000 1200
639 2001/8/9 2:46 Product1 1200 Mastercard Ken Sidcup England United Kingdom 11/26/07 16:44 2002/11/9 11:00 51.416667 0.116667 1200
640 1/26/09 7:11 Product1 1200 Visa Tori Minneapolis MN United States 11/22/08 21:06 2002/11/9 11:35 44.980000 -93.263610 1200
642 2001/9/9 8:35 Product1 1200 Amex Precious Edmonton Alberta Canada 2001/8/9 14:14 2002/11/9 14:26 53.550000 -113.500000 1200
643 1/24/09 3:25 Product1 1200 Visa Michelle Lyndoch South Australia Australia 9/26/08 19:23 2002/11/9 15:05 -34.616667 138.883333 1200
644 1/26/09 8:45 Product1 1200 Visa Paula Larchmont NY United States 2/15/06 17:21 2002/11/9 17:12 40.927780 -73.752220 1200
645 1/23/09 10:45 Product1 1200 Visa Stephanie Saint Charles IL United States 1/23/09 8:46 2002/11/9 17:57 41.914170 -88.308610 1200
646 1/28/09 8:50 Product1 1200 Visa kemp Brentwood TN United States 1/28/09 8:42 2002/11/9 18:41 36.033060 -86.782780 1200
648 2001/9/9 20:25 Product1 1200 Diners Mona Kelowna British Columbia Canada 2001/9/9 14:20 2002/11/9 20:19 49.900000 -119.483333 1200
649 1/15/09 21:53 Product1 1200 Visa Caroline Toronto Ontario Canada 2001/1/9 18:01 2002/11/9 21:01 43.666667 -79.416667 1200
650 2001/12/9 0:17 Product1 1200 Mastercard Andrea Brondby Strand Kobenhavn Denmark 2001/7/9 23:40 2002/11/9 22:23 55.616667 12.350000 1200
651 1/25/09 10:32 Product1 1200 Mastercard Pilar Florence Tuscany Italy 1/23/09 4:46 2002/12/9 2:22 43.766667 11.250000 1200
626 1/28/09 16:17 Product1 1200 Mastercard Zoe Coventry England United Kingdom 1/28/09 15:59 2002/10/9 19:55 52.416667 -1.550000 1200
625 1/19/09 11:05 Product1 1200 Visa Bertrand North Caldwell NJ United States 2010/3/8 5:55 2002/10/9 18:16 40.839720 -74.276940 1200
624 2001/2/9 14:14 Product1 1200 Diners Aaron Reading England United Kingdom 11/16/08 15:49 2002/10/9 16:38 51.433333 -1.000000 1200
623 1/29/09 15:03 Product1 1200 Visa Mary Auckland Auckland New Zealand 2002/9/6 11:14 2002/10/9 16:31 -36.866667 174.766667 1200
... ... ... ... ... ... ... ... ... ... ... ... ... ...
727 1/19/09 4:23 Product2 3600 Mastercard don Cagliari Sardinia Italy 1/13/08 11:41 2/16/09 0:22 39.216667 9.116667 3600
868 2001/6/9 20:39 Product2 3600 Mastercard Christiane Mission British Columbia Canada 2001/6/9 9:44 2/23/09 8:55 49.133333 -122.300000 3600
867 2001/8/9 11:14 Product2 3600 Visa Liz Langnau Zurich Switzerland 2001/7/9 10:25 2/23/09 7:17 47.283333 8.533333 3600
372 1/29/09 10:09 Product2 3600 Mastercard Jacqui Scottsdale AZ United States 1/29/09 9:59 1/29/09 12:58 33.509170 -111.898330 3600
863 1/15/09 15:56 Product2 3600 Visa Charmain Cartersburg IN United States 2001/2/8 10:51 2/23/09 6:24 39.698610 -86.463610 3600
620 1/24/09 13:54 Product2 3600 Mastercard Meredith Kloten Zurich Switzerland 1/24/09 12:30 2002/10/9 13:47 47.450000 8.583333 3600
901 1/16/09 5:12 Product2 3600 Visa Karen Berikon Aargau Switzerland 10/19/07 12:31 2/25/09 5:12 47.350000 8.383333 3600
290 1/26/09 3:49 Product2 3600 Mastercard Jane Biot Provence-Alpes-Cote d'Azur France 2003/1/8 0:00 1/26/09 3:18 43.633333 7.100000 3600
546 2001/2/9 22:44 Product2 3600 Visa eva Gisborne Victoria Australia 2012/3/6 15:36 2002/6/9 20:03 -37.483333 144.583333 3600
857 2001/12/9 10:08 Product2 3600 Mastercard Judy Washington DC United States 5/31/08 12:03 2/22/09 18:58 38.895000 -77.036670 3600
752 1/27/09 3:45 Product2 3600 Visa minjeong Bern Bern Switzerland 1/27/09 2:39 2/17/09 3:44 46.916667 7.466667 3600
195 2001/7/9 6:11 Product2 3600 Visa Tiffany Paris Ile-de-France France 2001/7/9 5:30 1/20/09 11:22 48.866667 2.333333 3600
755 1/24/09 17:18 Product2 3600 Visa Charlotte Sterling VA United States 2/15/08 15:34 2/17/09 6:26 39.006110 -77.428890 3600
312 1/20/09 7:08 Product2 3600 Visa Miye Downingtown PA United States 1/19/09 8:06 1/27/09 6:38 40.006390 -75.703610 3600
505 1/25/09 16:11 Product3 7500 Visa scott Rogers AR United States 1/25/09 15:55 2002/5/9 0:20 36.331940 -94.118330 7500
912 1/25/09 11:35 Product3 7500 Mastercard Anita Fresno TX United States 1/24/09 9:24 2/25/09 14:22 29.538610 -95.447220 7500
995 2001/1/9 4:24 Product3 7500 Amex Pamela Skaneateles NY United States 12/28/08 17:28 2003/1/9 7:21 42.946940 -76.429440 7500
434 1/14/09 10:32 Product3 7500 Mastercard Diana Campinas Sao Paulo Brazil 2011/5/8 7:03 2002/2/9 5:54 -22.900000 -47.083333 7500
511 1/25/09 1:53 Product3 7500 Visa Michael Pietermaritzburg KwaZulu-Natal South Africa 1/24/09 12:52 2002/5/9 4:37 -29.616667 30.383333 7500
206 1/16/09 2:41 Product3 7500 Visa Kristyn Kearns UT United States 1/15/09 18:01 1/21/09 1:02 40.660000 -111.995560 7500
814 2001/12/9 5:50 Product3 7500 Mastercard Brona Den Haag Zuid-Holland Netherlands 2001/4/5 12:43 2/20/09 0:24 52.083333 4.300000 7500
493 2001/11/9 4:29 Product3 7500 Visa Hans Knoxville TN United States 8/28/08 6:20 2002/4/9 12:17 35.960560 -83.920830 7500
244 2001/5/9 2:57 Product3 7500 Visa Marion Rennes Brittany France 12/29/08 3:16 1/23/09 7:29 48.083333 -1.683333 7500
932 1/17/09 7:56 Product3 7500 Diners Michel Lipari Sicilia Italy 1/17/09 7:25 2/26/09 7:32 38.466667 14.950000 7500
963 1/22/09 12:45 Product3 7500 Visa Frank and Christelle Valley Center CA United States 1/22/09 10:25 2/27/09 10:49 33.218330 -117.033330 7500
933 1/17/09 7:58 Product3 7500 Diners natalie Lipari Sicilia Italy 1/17/09 7:25 2/26/09 7:32 38.466667 14.950000 7500
544 1/15/09 10:16 Product3 7500 Visa Karin Olive Branch MS United States 2001/12/9 17:41 2002/6/9 18:48 34.961670 -89.829440 7500
189 1/20/09 5:24 Product3 7500 Mastercard Amanda Shreveport LA United States 1/20/09 5:13 1/20/09 7:15 32.525000 -93.750000 7500
150 1/18/09 13:26 Product3 7500 Mastercard Julianne Navan Meath Ireland 1/18/09 12:20 1/18/09 12:20 53.652778 -6.681389 7500
558 1/28/09 18:00 Product1 13000 Visa sandhya Centennial CO United States 2012/2/6 23:24 2002/7/9 15:18 39.579170 -104.876390 13,000
df.sort_values(['Price','City'],ascending=[False,True]) # 先按price 再按City排 先正序 后倒序
Transaction_date Product Price Payment_Type Name City State Country Account_Created Last_Login Latitude Longitude Price2
558 1/28/09 18:00 Product1 13000 Visa sandhya Centennial CO United States 2012/2/6 23:24 2002/7/9 15:18 39.579170 -104.876390 13,000
434 1/14/09 10:32 Product3 7500 Mastercard Diana Campinas Sao Paulo Brazil 2011/5/8 7:03 2002/2/9 5:54 -22.900000 -47.083333 7500
814 2001/12/9 5:50 Product3 7500 Mastercard Brona Den Haag Zuid-Holland Netherlands 2001/4/5 12:43 2/20/09 0:24 52.083333 4.300000 7500
912 1/25/09 11:35 Product3 7500 Mastercard Anita Fresno TX United States 1/24/09 9:24 2/25/09 14:22 29.538610 -95.447220 7500
206 1/16/09 2:41 Product3 7500 Visa Kristyn Kearns UT United States 1/15/09 18:01 1/21/09 1:02 40.660000 -111.995560 7500
493 2001/11/9 4:29 Product3 7500 Visa Hans Knoxville TN United States 8/28/08 6:20 2002/4/9 12:17 35.960560 -83.920830 7500
932 1/17/09 7:56 Product3 7500 Diners Michel Lipari Sicilia Italy 1/17/09 7:25 2/26/09 7:32 38.466667 14.950000 7500
933 1/17/09 7:58 Product3 7500 Diners natalie Lipari Sicilia Italy 1/17/09 7:25 2/26/09 7:32 38.466667 14.950000 7500
150 1/18/09 13:26 Product3 7500 Mastercard Julianne Navan Meath Ireland 1/18/09 12:20 1/18/09 12:20 53.652778 -6.681389 7500
544 1/15/09 10:16 Product3 7500 Visa Karin Olive Branch MS United States 2001/12/9 17:41 2002/6/9 18:48 34.961670 -89.829440 7500
511 1/25/09 1:53 Product3 7500 Visa Michael Pietermaritzburg KwaZulu-Natal South Africa 1/24/09 12:52 2002/5/9 4:37 -29.616667 30.383333 7500
244 2001/5/9 2:57 Product3 7500 Visa Marion Rennes Brittany France 12/29/08 3:16 1/23/09 7:29 48.083333 -1.683333 7500
505 1/25/09 16:11 Product3 7500 Visa scott Rogers AR United States 1/25/09 15:55 2002/5/9 0:20 36.331940 -94.118330 7500
189 1/20/09 5:24 Product3 7500 Mastercard Amanda Shreveport LA United States 1/20/09 5:13 1/20/09 7:15 32.525000 -93.750000 7500
995 2001/1/9 4:24 Product3 7500 Amex Pamela Skaneateles NY United States 12/28/08 17:28 2003/1/9 7:21 42.946940 -76.429440 7500
963 1/22/09 12:45 Product3 7500 Visa Frank and Christelle Valley Center CA United States 1/22/09 10:25 2/27/09 10:49 33.218330 -117.033330 7500
563 1/25/09 17:58 Product2 3600 Visa carol Ann Arbor MI United States 2007/5/8 9:20 2002/7/9 18:51 42.270830 -83.726390 3600
894 1/27/09 14:42 Product2 3600 Mastercard Jean Arlington VA United States 2001/8/9 11:01 2/24/09 16:38 38.890280 -77.084440 3600
987 1/23/09 12:42 Product2 3600 Mastercard Anke Avalon New South Wales Australia 2003/3/8 17:38 2/28/09 22:26 -33.633333 151.333333 3600
799 1/30/09 6:18 Product2 3600 Mastercard Louise Balgach St Gallen Switzerland 1/14/06 2:40 2/19/09 7:10 47.416667 9.600000 3600
523 2001/8/9 19:29 Product2 3600 Mastercard PATRICK Ban Khlong Sip Krung Thep Thailand 2001/8/9 0:01 2002/5/9 21:22 13.916667 100.816667 3600
898 2001/8/9 2:49 Product2 3600 Mastercard Caroline Begnins Vaud Switzerland 2001/7/9 4:14 2/25/09 1:37 46.433333 6.250000 3600
432 2001/12/9 10:05 Product2 3600 Amex Pamela Bellinzona Ticino Switzerland 2009/3/7 13:23 2002/2/9 5:16 46.200000 9.016667 3600
901 1/16/09 5:12 Product2 3600 Visa Karen Berikon Aargau Switzerland 10/19/07 12:31 2/25/09 5:12 47.350000 8.383333 3600
752 1/27/09 3:45 Product2 3600 Visa minjeong Bern Bern Switzerland 1/27/09 2:39 2/17/09 3:44 46.916667 7.466667 3600
175 1/14/09 5:20 Product2 3600 Visa Kristen Binningen Basel-Country Switzerland 2001/12/9 13:31 1/19/09 13:07 47.533333 7.566667 3600
290 1/26/09 3:49 Product2 3600 Mastercard Jane Biot Provence-Alpes-Cote d'Azur France 2003/1/8 0:00 1/26/09 3:18 43.633333 7.100000 3600
994 1/28/09 5:36 Product2 3600 Visa Christiane Black River Black River Mauritius 2001/9/9 8:10 2003/1/9 4:40 -20.360278 57.366111 3600
172 2001/8/9 11:55 Product2 3600 Visa Caren Braunschweig Lower Saxony Germany 2001/3/9 12:39 1/19/09 8:31 52.266667 10.533333 3600
573 1/26/09 1:44 Product2 3600 Visa Geraldine Brussels Brussels (Bruxelles) Belgium 1/31/08 13:28 2002/8/9 14:39 50.833333 4.333333 3600
... ... ... ... ... ... ... ... ... ... ... ... ... ...
410 2001/7/9 13:49 Product1 1200 Diners megan West Hills CA United States 2001/7/9 12:36 2002/1/9 8:20 34.201110 -118.597220 1200
138 1/17/09 16:22 Product1 1200 Visa Chad West Orange NJ United States 1/17/09 15:22 1/17/09 18:42 40.798610 -74.239440 1200
710 1/25/09 17:48 Product1 1200 Visa olla Westminster CO United States 1/24/09 23:48 2/15/09 8:08 39.836670 -105.036670 1200
391 1/31/09 7:22 Product1 1200 Visa Monica Weston CT United States 2/29/08 17:34 1/31/09 6:43 41.200830 -73.381110 1200
575 1/24/09 21:26 Product1 1200 Visa Olivia Wheaton IL United States 2005/8/8 16:02 2002/8/9 16:00 41.866110 -88.106940 1200
287 2001/9/9 10:22 Product1 1200 Mastercard HELIDA White House TN United States 2001/5/9 14:49 1/25/09 19:35 36.470280 -86.651390 1200
187 1/20/09 3:11 Product1 1200 Visa Randy Wigan England United Kingdom 1/20/09 3:02 1/20/09 3:06 53.533333 -2.616667 1200
782 1/19/09 14:06 Product1 1200 Mastercard Elisabeth Wilmington NC United States 1/19/09 12:41 2/18/09 8:18 34.225560 -77.945000 1200
874 1/21/09 7:31 Product1 1200 Mastercard Beatrice Wilmington DE United States 3/25/08 13:23 2/23/09 16:29 39.745830 -75.546940 1200
236 1/20/09 8:51 Product1 1200 Visa Marie Winchester MA United States 7/23/08 14:59 1/22/09 18:08 42.452220 -71.137500 1200
162 1/13/09 20:59 Product1 1200 Mastercard Andrew Winnipeg Manitoba Canada 1/13/09 16:44 1/18/09 19:17 49.883333 -97.166667 1200
228 2001/12/9 9:23 Product1 1200 Mastercard Jacob Winter Haven FL United States 2001/10/9 14:55 1/22/09 7:59 28.021940 -81.733060 1200
936 2001/11/9 8:41 Product1 1200 Amex Juliann Winter Spgs FL United States 2001/8/8 7:24 2/26/09 8:17 28.698610 -81.308330 1200
600 1/14/09 13:23 Product1 1200 Diners eugenia Wisconsin Rapids WI United States 11/15/08 13:57 2002/9/9 18:44 44.383610 -89.817220 1200
207 1/16/09 18:36 Product1 1200 Visa Elizabeth Wollongong New South Wales Australia 2011/1/8 16:32 1/21/09 1:49 -34.433333 150.883333 1200
678 1/14/09 16:02 Product1 1200 Mastercard Jessica Woodland Hills CA United States 1/14/09 14:53 2/13/09 16:45 34.168330 -118.605000 1200
66 2001/8/9 15:16 Product1 1200 Visa Dottie Woodsboro MD United States 2001/8/9 14:56 2001/12/9 9:29 39.533060 -77.315000 1200
748 1/25/09 7:29 Product1 1200 Diners Howard Worcester England United Kingdom 1/22/09 14:02 2/17/09 3:00 52.200000 -2.200000 1200
982 2001/4/9 18:57 Product1 1200 Mastercard KELI Worongary Queensland Australia 12/23/08 15:17 2/28/09 14:00 -28.050000 153.350000 1200
156 2001/4/9 23:48 Product1 1200 Diners Sarka Yellowknife Northwest Territories Canada 2001/4/9 22:41 1/18/09 16:17 62.450000 -114.350000 1200
680 2001/8/9 20:52 Product1 1200 Visa Pam and Rob Yorba Linda CA United States 11/18/08 20:03 2/13/09 19:32 33.888610 -117.812220 1200
129 1/15/09 10:24 Product1 1200 Visa Grace York England United Kingdom 1/13/09 12:30 1/17/09 4:42 53.966667 -1.083333 1200
469 1/24/09 10:23 Product1 1200 Visa DD York England United Kingdom 8/19/08 12:58 2002/3/9 12:57 53.966667 -1.083333 1200
530 1/19/09 3:19 Product1 1200 Mastercard TG Zagore Stara Zagora Bulgaria 11/20/08 3:00 2002/6/9 4:19 42.350000 25.666667 1200
169 2001/3/9 9:54 Product1 1200 Visa Sylvia Zekeriyakoy Istanbul Turkey 12/29/08 10:38 1/19/09 7:37 41.198056 29.030278 1200
905 1/23/09 5:52 Product1 1200 Amex Tary Zug Zug Switzerland 1/23/09 1:22 2/25/09 9:40 47.166667 8.516667 1200
798 1/21/09 11:56 Product1 1200 Visa Katrin Zumikon Zurich Switzerland 3/21/06 13:30 2/19/09 7:05 47.333333 8.616667 1200
515 1/25/09 8:50 Product1 1200 Mastercard Shane Zurich Zurich Switzerland 1/24/09 12:23 2002/5/9 11:07 47.366667 8.550000 1200
294 1/21/09 11:28 Product1 800 Amex Heloise Arlington VA United States 9/25/05 20:26 1/26/09 6:23 38.890280 -77.084440 800
477 1/30/09 7:42 Product1 250 Visa Tabatha Altadena CA United States 12/28/08 14:42 2002/3/9 18:09 34.189720 -118.130280 250
#groupby
df.groupby(df.Country).mean().sort_values('Price',ascending=False) #按平均值分类 再排序
Price Latitude Longitude
Country
Mauritius 3600.000000 -20.360278 57.366111
Russia 3600.000000 55.628333 37.660833
Italy 2520.000000 42.895556 11.368889
Brazil 2460.000000 -20.486944 -46.100333
South Africa 2460.000000 -27.538222 29.150778
Thailand 2400.000000 10.900000 99.608333
Malta 2400.000000 35.979028 14.368333
Switzerland 2133.333333 46.846296 7.526852
Netherlands 2031.818182 52.241667 4.870455
United Arab Emirates 2000.000000 25.107130 55.117037
Czech Republic 2000.000000 50.142778 14.898056
France 1966.666667 47.174691 4.074691
Sweden 1753.846154 59.428205 17.692308
Australia 1705.263158 -33.028465 144.039225
Germany 1680.000000 50.322000 9.614667
Canada 1642.105263 48.280482 -99.206360
United States 1619.870410 37.510644 -93.057584
Austria 1542.857143 48.145238 15.697619
Belgium 1500.000000 50.835417 4.325000
United Kingdom 1440.000000 52.371276 -1.307689
Ireland 1426.530612 52.923997 -7.132545
Spain 1400.000000 40.227269 -1.922523
Norway 1350.000000 59.776944 8.537483
Moldova 1200.000000 46.985000 28.942500
Monaco 1200.000000 43.733333 7.416667
New Zealand 1200.000000 -37.651389 174.558333
The Bahamas 1200.000000 25.791667 -78.058333
Philippines 1200.000000 8.008611 124.654583
Turkey 1200.000000 40.590648 28.702546
Romania 1200.000000 44.466667 26.133333
Ukraine 1200.000000 50.516667 30.250000
South Korea 1200.000000 37.533333 127.116667
Poland 1200.000000 53.258333 19.750000
Argentina 1200.000000 -37.150000 -58.483333
Malaysia 1200.000000 3.166667 101.700000
Luxembourg 1200.000000 49.585556 6.123056
Bahrain 1200.000000 26.217222 50.540556
Bermuda 1200.000000 32.294167 -64.783889
Bulgaria 1200.000000 42.350000 25.666667
Cayman Isls 1200.000000 19.300000 -81.383333
China 1200.000000 22.250000 112.783333
Costa Rica 1200.000000 10.033333 -84.150000
Denmark 1200.000000 55.655667 12.110037
Dominican Republic 1200.000000 18.466667 -69.900000
Finland 1200.000000 61.933333 26.675000
Greece 1200.000000 37.983333 23.733333
Guatemala 1200.000000 14.650000 -90.483333
Hong Kong 1200.000000 22.283333 114.150000
Hungary 1200.000000 47.255556 19.277778
Iceland 1200.000000 63.850000 -21.366667
India 1200.000000 22.925000 77.750000
Israel 1200.000000 32.066667 34.766667
Japan 1200.000000 35.659167 139.700694
Kuwait 1200.000000 29.289167 48.050000
Latvia 1200.000000 57.033333 24.100000
Jersey 1200.000000 49.200000 -2.033333
# join on
df2 = pd.DataFrame([['MO',0],['OR',1],['AL',2]],columns=['State','v']) #构建一个新表
df2
State v
0 MO 0
1 OR 1
2 AL 2
pd.merge(df2,df,on='State',how='left')
State v Transaction_date Product Price Payment_Type Name City Country Account_Created Last_Login Latitude Longitude Price2
0 MO 0 2001/2/9 4:53 Product1 1200 Visa Betina Parkville United States 2001/2/9 4:42 2001/2/9 7:49 39.19500 -94.68194 1200
1 OR 1 2001/2/9 13:08 Product1 1200 Mastercard Federica e Andrea Astoria United States 2001/1/9 16:21 2001/3/9 12:32 46.18806 -123.83000 1200
2 OR 1 1/17/09 7:23 Product1 1200 Visa Georgina Portland United States 11/28/07 10:05 1/24/09 8:54 45.52361 -122.67500 1200
3 AL 2 2001/4/9 12:56 Product2 3600 Visa Gerd W Cahaba Heights United States 11/15/08 15:47 2001/4/9 12:45 33.52056 -86.80250 3600
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容