pandas表格数据-删除/赋值/字符串包含等

官网:https://www.pypandas.cn/docs/

1.删除某一固定列
del df['列名']

  1. 删除某列某部分内容,以.str[0]取值

df['开始时间']=df['开始时间'].str.split('到').str[0]

3.取值使用loc()函数
df1.loc[(df1[0]'js') & (df1[2]'cz'),[1,3]]=[588,688]

4.判断字符串是否包含在某一列里
mask=df['日期'].str.contains(r'休息',na=True)
不包含
nomask=~ df['日期'].str.contains(r'休息',na=True)
5.数据比较

数据类型转换

df.dtypes # 查看数据类型
df.index.astype('int64') # 索引类型转换
df.astype('int32') # 所有数据转换为 int32
df.astype({'col1': 'int32'}) # 指定字段转指定类型
s.astype('int64')
s.astype('int64', copy=False) # 不与原数据关联
s.astype(np.uint8)
df['name'].astype('object')
data['Q4'].astype('float')
s.astype('datetime64[ns]')
data['状态'].astype('bool')

参考网址:https://blog.csdn.net/weixin_43790276/article/details/116616312

数据转换:https://www.jb51.net/article/139630.htm

原文地址:https://www.cnblogs.com/luoditao/p/14927098.html