import pandas as pd
import sys
%matplotlib inline
print('Python version ' + sys.version)
print('Pandas version ' + pd.__version__)
Python version 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] Pandas version 1.0.5
# dataframe
df = pd.DataFrame(data={'col1':[0,10,2,30,4]})
df
col1 | |
---|---|
0 | 0 |
1 | 10 |
2 | 2 |
3 | 30 |
4 | 4 |
# Sort by col1 ascending
df.sort_values(by='col1')
col1 | |
---|---|
0 | 0 |
2 | 2 |
4 | 4 |
1 | 10 |
3 | 30 |
# Unordered index
d = {'col2':[22,10,113]}
i = [pd.Timestamp('20130102'),
pd.Timestamp('2013-01-01'),
pd.Timestamp('1/3/2013')]
df = pd.DataFrame(data=d, index = i)
df
col2 | |
---|---|
2013-01-02 | 22 |
2013-01-01 | 10 |
2013-01-03 | 113 |
# Index sorted ascending
df.sort_index()
col2 | |
---|---|
2013-01-01 | 10 |
2013-01-02 | 22 |
2013-01-03 | 113 |
This tutorial was created by HEDARO