①只输出指定的列
输出WC_DF2中的"city_ascii","population"两列
WC_DF2 = WC_DF2[["city_ascii","population"]]
②筛选 满足对应条件的行
筛选出国家为“China”的行
WC_DF2 = WC_DF2[WC_DF2['country'] == "China"]
③对某一列求和
求population列的总和
WC_DF2['population'].sum()
④新建一列,并通过外部函数赋值
新建列distance_from_loc,将值放进列表distance_l,再赋值
(这里列的值通过外部函数haversine_distance计算得出)
distance_l = []
for i in LOC:
distance_l.append(haversine_distance(loc, i))
QUAKE_DF2['distance_from_loc'] = distance_l
⑤遍历dataFrame每一行,对其中元素进行操作
遍历filtered_DF中的每一行
for c_row in filtered_DF.itertuples():
loc1 = getattr(c_row, 'lat'),getattr(c_row, 'lng')