Pandas¶
a | b | c | text | |
---|---|---|---|---|
0 | 4 | 7.0 | 10.0 | 我 |
1 | 4 | 8.0 | 11.0 | 今天 |
2 | 6 | 9.0 | 12.0 | 沒 |
3 | 5 | 15.0 | 20.0 | 吃飽 |
Basic Data Frame Manitpulation¶
Sort Values¶
df.sort_values('a')
df.sort_values('a',ascending=False)
Columns¶
df.drop(columns=['a','c'])
df[list_of_COLNAMES]
:df[['a','b','c']]
returns df
df.select_dtypes(include=['float64'])
df.select_dtypes(exclude=['float64'])
df[COLNAME]
:df['width']
returns series
Rows¶
df.head()
,df.tail()
df.iloc[:3]
df[df["a"] > 4]
,df[~(df["a"] > 4)]
df[df['a'].isin({5, 6})]
df.drop_duplicates()
df.sample(frac=0.5)
, df.sample(n=100)
Rows + Columns¶
df.iloc[:3, [0, 2]]
df.iloc[:3][['a', 'b']]
Text Processing¶
Iteration¶
a | b | c | text | new_text | |
---|---|---|---|---|---|
0 | 4 | 7.0 | 10.0 | 我 | 今天星期日 |
1 | 4 | 8.0 | 11.0 | 今天 | 今天星期一 |
2 | 6 | 9.0 | 12.0 | 沒 | 今天星期二 |
3 | 5 | 15.0 | 20.0 | 吃飽 | 今天星期三 |
Plotting¶
Setting up matplotlib
display options in Jupyter notebook¶
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (8, 5)
plt.rcParams['font.family'] = ['AR PL KaitiM Big5'] # Custom font (installed on computer, .ttf format)
plt.rcParams['font.sans-serif'] = ['DejaVu Sans'] # Custom font (installed on computer, .ttf format)
plt.rcParams.update({'font.size': 18})
plt.rcParams['axes.unicode_minus'] = False
Miscellaneous¶
a | b | c | |
---|---|---|---|
a | 1.000000 | 0.363270 | 0.323531 |
b | 0.363270 | 1.000000 | 0.998765 |
c | 0.323531 | 0.998765 | 1.000000 |
a | text | new_text | |
---|---|---|---|
0 | 4 | 我 | 今天星期日 |
1 | 4 | 今天 | 今天星期一 |
2 | 6 | 沒 | 今天星期二 |
3 | 5 | 吃飽 | 今天星期三 |