user_id
의 빈도 (2 회 이상 게시 한 사용자)로 필터링하려고하는 위치가 지정된 소셜 미디어 게시물의 데이터 세트가 있습니다. . 나는 이것을 만들고 싶기 때문에 내가 만드는 궤도 데이터를 더 깨끗하게 정리할 수 있습니다.필터 열 개수에 의한 팬더 수와 데이터 쓰기
샘플 코드 :
# Import Data
data = pd.read_csv('path', delimiter=',', engine='python')
#print len(data),"rows"
#print data
# Create Data Fame
df = pd.DataFrame(data, columns=['user_id','timestamp','latitude','longitude'])
#print data.head()
# Get a list of unique user_id values
uniqueIds = np.unique(data['user_id'].values)
# Get the ordered (by timestamp) coordinates for each user_id
output = [[id,data.loc[data['user_id']==id].sort_values(by='timestamp')['latitude','longitude'].values.tolist()] for id in uniqueIds]
# Save outputs
outputs = pd.DataFrame(output)
#print outputs
outputs.to_csv('path', index=False, header=False)
내가 USER_ID의 수를 얻을하고 그러나 라인 output = [[......data['user_id']==id>1].....
에서> (1)을 통과 df[].value_counts()
를 사용하여 시도, 작동하지 않았다. 코드에 추가 인수로 user_id
의 빈도를 추가하여 해당 사용자에 대한 정보 만 추출 할 수 있습니까?
샘플 데이터 :
user_id, timestamp, latitude, longitude
478134225, 3/12/2017 9:04, 38.8940974, -77.0276216
478103585, 3/12/2017 9:04, 38.882584, -77.1124701
478073193, 3/12/2017 9:07, 39.00027849, -77.09480086
476194185, 3/12/2017 9:14, 38.8048355, -77.0469214
476162349, 3/12/2017 9:16, 38.8940974, -77.0276216
478073193, 3/12/2017 9:05, 38.8549, -76.8752
477899275, 3/12/2017 9:08, 38.90181532, -77.03733586
477452890, 3/12/2017 9:08, 38.96117237, -76.95561893
478073193, 3/12/2017 9:05, 38.7188716, -77.1542684
가능한 복제 [파이썬 팬더 : 특정 주파수 카운트 아래 행을 제외 (http://stackoverflow.com/questions/30485151/python-pandas-exclude-rows-below-a-certain-frequency- 카운트) –