![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pandas数据分析
不染pigpig
行动养成习惯,习惯成为自律,自律塑造人格,人格拥有独特的灵魂和魅力
展开
-
pandas 去空值
去任意有空值的行df.dropna(axis=0, how='any', inplace=True)axis:0: 行操作(默认)1: 列操作how:any: 只要有空值就删除(默认)all:全部为空值才删除inplace:False: 返回新的数据集(默认)True: 在愿数据集上操作检查空值print(df.isnull()) # 是空值返回True,否则返回Falseprint(np.any(df2.isnull())) # 只要有一个空值便会返回True,否则返回Fa原创 2021-11-10 11:18:54 · 5791 阅读 · 0 评论 -
pandas 遍历txt, excel文档 按替换数值
columns = data.columns.values.tolist() ##获取excel 表头 ,第一行for index, row in data.iterrows(): ### 迭代数据 以键值对的形式 获取 每行的数据 for column in columns: if column == "材料": data.loc[index, column] = data.loc[index, "材料"] elif col原创 2021-09-25 17:12:28 · 203 阅读 · 0 评论 -
字符串的方法
转载:https://www.runoob.com/python/python-strings.htmldata[[“alleles1”,“alleles2”]] = data[[“alleles1”,“alleles2”]]*2AA原创 2021-09-25 17:07:32 · 47 阅读 · 0 评论 -
pandas 删除列 多列
使用del和drop方法删除DataFrame中的列,使用drop方法一次删除多列# 使用del, 一次只能删除一列,不能一次删除多列 # 只能使用 del df['密度'], 不能使用 del df[['密度', '含糖率']] del df['密度'] # del df[['密度', '含糖率']] 报错 # 使用drop,有三种方法: dt = dt.drop(['密度', '含糖率'], axis=1) # axis=1 表示删除列,['密度', '含糖率'] 要删除的co原创 2021-09-25 17:03:56 · 8648 阅读 · 0 评论 -
Panda 增加列(单列和多列)
增添一列(1)insert 方法使用 pandas 的 insert 方法,第一个参数指定插入列的位置,第二个参数指定插入列的列名,第三个参数指定插入列的数据。data.insert(data.shape[1], 'd', 0)data a b c d 0 1 2 3 0 1 4 5 6 0 2 7 8 9 0df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})df col1 col20原创 2021-09-18 11:11:01 · 7402 阅读 · 0 评论