数据格式
这里写目录标题
单元格格式(数据类型)
基础
df.dtypes # 各字段的数据类型
df.team.dtype # 某个字段的类型
s.dtype # Series 的类型
df.dtypes.value_counts() # 各类型有多少个字段
判断数据格式
from pandas.api.types import is_numeric_dtype
#导入is_numeric_dtype工具
is_numeric_dtype(df_member['总消费'])
#是否为数值字段?
数字格式
1 设置小数位数
#四舍五入保留2位小数
df['float格式'].round(decimals=2)#decimals参数是设置保留小数的位数
#a列保留一位小数,b列保留2位小数
df.round(decimals={'a':1,'b':2})
#用自定义函数设置
df['float格式'].map(lambda x :('%.2f')%x)
df['float格式'].map(lambda x :"{:.1f}".format(x))
df['A'].map(lambda x: format(x, ".1f"))
df.style.format(precision=0,na_rep='')#设置小数点位数为0
df.style.format('{:.2f}',na_rep='')#设置小数点位数为2
df.style.format({'A':'{:.2f}',
'B'