import pandas as pd
import numpy as np
a =[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
d =[10, 21, 10, 21, 21, 10, 23, 23, 25, 25]
f =[0, 1, 1, 2, 0, 0, 2, 2, 0, 0]df= pd.DataFrame({'id': a, 'geom': d, 'type': f})#df= df[['id', 'geom', 'type']]
df_group = df.groupby('geom')for i, j in df_group:
print("j:", j)
unique_values = j['type'].unique()# 第一种情况:都是非重要的节点if len(unique_values)==1 and unique_values[0]==0:
print("将这个dataframe只保留一条数据")
else:
# 1、先将type为节点的数据删除(数据库中删除)
df_normal = j[j['type']==0]
print("df_normal:", df_normal)# 2、判断df_的大小,如果只有一条的不用管,大于一条的修改坐标
df_ = j[j['type']!=0]
print("df_:",df_)if len(df_)!=1:
number = np.concatenate(([0], np.arange(0.1,(df_.shape[0] -1)*0.1+0.1,0.1)))
df_['geom']= df_['geom'] + number
print("df_更改后:", df_)
结果
j: id geom type011002310156100
df_normal: id geom type0110056100
df_: id geom type23101
j: id geom type122113421245210
df_normal: id geom type45210
df_: id geom type1221134212
df_更改后: id geom type1221.013421.12
j: id geom type6723278232
df_normal: Empty DataFrame
Columns: [id, geom, type]
Index: []
df_: id geom type6723278232
df_更改后: id geom type6723.027823.12
j: id geom type89250910250
将这个dataframe只保留一条数据