一、create an example DataFrame
二、rename columns
df = df.rename({
'col one':'col_one', 'col two':'col_two'}, axis='columns')
or
df.columns = ['col_one', 'col_two']
or
df.columns = df.columns.str.replace(' ', '_')
or
df.add_prefix('X_')
三、reverse row order
四、reverse column order
五、select columns by data type
drinks.select_dtypes(include='number').head()
or
drinks.select_dtypes(include='object').head()
or
drinks.select_dtypes(include=['object', 'number', 'category', 'datetime']).head()
or
drinks.select_dtypes(exclude='number').head()
六、convert strings to numbers
将NaN置0:
七、Reduce DataFrame size
pandas DataFrames are designed to fit into memory, so sometimes you need to reduce the DataFrame size
step1:只加载需要的columns:
step2:转换成category类型:
八、Build a DataFrame from multiple files(row-wise)
九、Build a DataFrame from multiple files(column-wise)
十、Create a DataFrame from a clipboard
step1:将表格中的内容复制
step2: run the codes
如果要复用,不建议使用read_clipboard()方法
十一、Split a DataFrame into two random subsets
十二、Filter a DataFrame by multiple categories
十三、Filter a DataFrame by largest categories
十四、Handle missing values
十五、Split a string into multiple columns
十六、Expand a Series of lists into a DataFrame
十七、 Reshape a MultiIndexed Series
十八、Create a pivot table
十九、Convert continuous(连续的) data into categorical(离散的) data I think it’s useful
二十、Change display options
二十一、Style a DataFrame
example1:
example2:
example3:
example4:
Bonus: Profile a DataFrame(查看一个DataFrame的简要概括)