<p><a href="https://stackoverflow.com/questions/26483254/python-pandas-insert-list-into-a-cell">You can insert</a><code>list</code>到<code>pandas.DataFrame()</code>只使用<code>.set_value()</code>方法。列类型应该是<code>object</code>。在</p>
<pre><code>df = pd.DataFrame({"FDT_DATE":[1417390467000, 1417390428000, 1417390608000, 1417390548000,
1417390668000, 1417390717000, 1417390758000, 1417390798000, 1417390818000,
1417390827000, 1417390907000], "FFLT_LATITUDE":[31.2899, 31.291, 31.2944, 31.294,
31.2954, 31.2965, 31.2946, 31.2932, 31.294, 31.2946, 31.2952],
"FFLT_LONGITUDE":[121.4845, 121.4859, 121.4857, 121.485, 121.4886, 121.4937,
121.494, 121.496, 121.4966, 121.4974, 121.4986],
"FINT_STAT":[0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0],
"FSTR_ID":[112609, 112609, 112609, 112609, 112609, 112609, 112609, 112609,
112609, 112609, 112609]})
df = df.sort(['FDT_DATE']).reset_index(drop=True).reset_index()
def func(x):
global a
global b
if (x['index'] - x['FINT_STAT']) != x['index']:
return a
else:
b += 1
a = b
# Create 't1' column for filter "1" groups in 'FINT_STAT' column
a = 0
b = 0
df['t1'] = df[['index', 'FINT_STAT']].apply(lambda x: func(x), axis=1)
# Initialize result dataframe
df_res = df.drop_duplicates(subset=['t1'])[['FSTR_ID', 'FDT_DATE', 't1']].copy()\
.reset_index(drop=True)
df_res = df_res.dropna().reset_index(drop=True)
# First create 'POLYLINE' column then convert it into 'object'
df_res['POLYLINE'] = np.nan
df_res['POLYLINE'] = df_res['POLYLINE'].astype(object)
# Inserting list into dataframe is available with 'pd.DataFrame.set_value()
for i in df['t1'].dropna().unique():
df_res.set_value(df_res.loc[df_res['t1'] == i, 't1'].index.tolist()[0], 'POLYLINE',
df.loc[df['t1'] == i, ['FFLT_LATITUDE', 'FFLT_LONGITUDE']].values.tolist())
df_res = df_res.drop(['t1'], axis=1)
</code></pre>
<p>结果是(您发布的结果不按“FDT_DATE”排序):</p>
^{pr2}$