Pandas 如何将 2 列数据框转换为系列?

The*_*ash 2 python-3.x pandas

在这里,我想将 2 列数据框转换为新系列。“max”应该是索引,“price”是新系列的值。怎么做 ?我下面使用的方式似乎不正确: pd.Series(a['max'], index=a['price'])

>>> a
      price  max
0       4.0   86
1       5.0   87
2       6.0   88
3       7.0   91
4       8.0   91
..      ...  ...
385  1900.0   98
386  2000.0   97
387  2013.0   91
388  2500.0   96
389  3300.0   88

[390 rows x 2 columns]
>>> type(a)
<class 'pandas.core.frame.DataFrame'>
Run Code Online (Sandbox Code Playgroud)

WeN*_*Ben 5

你可以做

s=df.set_index('max')['price']
Run Code Online (Sandbox Code Playgroud)