一、How to avoid a SettingWithCopyWarning in pandas?

condition1:
Pandas使用教程(七)
condition2:
Pandas使用教程(七)

因为pandas不知道top_movies是view还是copy,所以会弹出警告,以下是解决方法:
Pandas使用教程(七)

二、How to change display options in pandas?

pd.set_option()
Pandas使用教程(七)
显示所有条目

pd.reset_option(‘display.max_rows’)会恢复默认设置

显示每列中的所有字符串
Pandas使用教程(七)
改变显示小数点的位数
Pandas使用教程(七)
给某一列的数字加上“,”(千分位)
Pandas使用教程(七)
bonus1:pd.describe_option():显示所有display方法(没有网络连接的情况下也可用),当只记得方法的一部分名称时,可以使用pd.describe_option(‘rows’) 显示所有名称包含rows的方法

bonus2:(and this is important):reset all of the options to the default:pd.reset_option(‘all’)

三、How to create a pandas DataFrame from another object?

1.创建一个DataFrame
Pandas使用教程(七)
改变默认index:
Pandas使用教程(七)
另一种DataFrame创建方法:用列表
Pandas使用教程(七)
改变行的名称:
Pandas使用教程(七)
2.convert a numpy array to a DataFrame
Pandas使用教程(七)
快速创建一个10行2列的DataFrame:
Pandas使用教程(七)

bonus:将Series连接到DataFrame(对应index)
Pandas使用教程(七)

四、map,apply,applymap

1.map() is a Series method
Pandas使用教程(七)
2.apply()既是Series方法也是DataFrame方法

1)作为Series方法:

example1:
Pandas使用教程(七)

example2:

Pandas使用教程(七)
example3:取姓名第一个逗号前的字符串

Pandas使用教程(七)

下面的代码与之作用相同:

Pandas使用教程(七)

2)作为DataFrame方法:

example1:

Pandas使用教程(七)
example2:

Pandas使用教程(七)

3.applymap()是DataFrame方法:改变DataFrame的所有元素

Pandas使用教程(七)

Pandas使用教程(七)

相关文章: