728x90
In [1]:
import pandas as pd
In [2]:
prices = pd.read_csv('/content/sample_data/prices.csv', squeeze=True)
In [3]:
# sort the values : that nothing changed in memory
# default: 오름차순
prices.sort_values()
Out[3]:
299984 -11062.06
299983 -11062.06
40984 0.00
345010 0.00
345008 0.00
...
16356 13541.33
43703 16453.71
43702 16888.02
524602 17836.46
222681 38970.00
Name: Price, Length: 541910, dtype: float64
In [5]:
# 옵션을 주면 memory가 바뀐다.
prices.sort_values(inplace=True)
In [6]:
# the indexes are now changed
prices
Out[6]:
299984 -11062.06
299983 -11062.06
40984 0.00
345010 0.00
345008 0.00
...
16356 13541.33
43703 16453.71
43702 16888.02
524602 17836.46
222681 38970.00
Name: Price, Length: 541910, dtype: float64
In [8]:
# sort by index
prices.sort_index(inplace=True)
In [9]:
prices
Out[9]:
0 2.55
1 3.39
2 2.75
3 3.39
4 3.39
...
541905 2.10
541906 4.15
541907 4.15
541908 4.95
541909 18.00
Name: Price, Length: 541910, dtype: float64
In [10]:
# sort the values in a decending order: 내림차순
prices.sort_values(ascending=False)
Out[10]:
222681 38970.00
524602 17836.46
43702 16888.02
43703 16453.71
16356 13541.33
...
388727 0.00
339441 0.00
40089 0.00
299983 -11062.06
299984 -11062.06
Name: Price, Length: 541910, dtype: float64
728x90
댓글