The_flash
The_flash

Reputation: 184

Pandas how to convert 2 columns of dataframe to series?

here, I would like to convert a 2 columns dataframe to New series. 'max' is suppose to be the index and 'price' is the value of the new Series. how to do that ? the way I used below seems incorrect: 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'>

Upvotes: 2

Views: 1402

Answers (1)

BENY
BENY

Reputation: 323266

You can do

s=df.set_index('max')['price']

Upvotes: 5

Related Questions