第1关:字符串操作方法
编程要求 要求实现如下功能:
- 读取step1/bournemouth_venues.csv文件,文件说明如下:
列名 | 说明 |
---|
Venue Name | 场地名 | Venue Category | 场地类别 | Venue Latitude | 场地经度 | | | Venue Longitude | 场地纬度 |
测试输入:
无测试输入
预期输出:
0 Roast
1 DelMarco
2 Gardens
3 Gardens
4 Square
5 Stable
6 Starbucks
7 Co.
8 Gardens
9 Sandwich
10 Kitchen
11 Gym
12 Coffee
13 Bournemouth
14 Manger
15 Cucumber
16 Guys
17 Club
18 Beach
19 Odeon
20 Gelateria
21 Valerie
22 Greek
23 Slope)
24 Starbucks
26 Nero
28 Tealith
29 NEO
30 Bay
31 Aces
...
67 Co.
69 Garden
70 Brasserie
71 Restaurant
72 Gardens
73 Atlantico
74 Hotel
75 DYMK
76 Winchester
77 Subway
78 Circus
79 Bar
80 Triangle
81 Rojo
82 KFC
83 Hotel
84 Cliff
85 Xchange
86 Express
87 (Harvester)
88 Zag
89 (BMH)
90 Bournemouth
91 Coffee
92 Inn
93 Stop
94 Chineside
96 Hotel
97 Hotel
98 Chine
Name: Venue Name, Length: 90, dtype: object
参考代码
import pandas as pd
def demo():
d=pd.read_csv('./step1/bournemouth_venues.csv')
d=d['Venue Name']
d=d.str.split().str.get(-1)
d=d.str.replace("P.*","")
d.drop(d[d.values==""].index,inplace = True)
d1=d.str.contains("[a-zA-Z]+")
d.drop(d1[d1==False].index,inplace=True)
return d
|