【问题标题】:Select columns with numbers only, no strings选择只有数字的列,没有字符串
【发布时间】:2023-03-16 21:17:01
【问题描述】:

我正在使用 hads 数据集。该集合包含许多家庭条目,其中许多变量与每个家庭相关联。在这些变量列中,其中许多是用“variable_info_here”表示的字符串,我想创建一个新的数据框,其中仅包含仅包含数字的变量。由于变量很多,我不知道哪些变量只包含数字。有没有快速检查的方法?

【问题讨论】:

    标签: pandas


    【解决方案1】:

    要选择带有数字的列,请尝试:

    df.select_dtypes(include=[np.number])
    

    https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.select_dtypes.html

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 2014-12-19
      • 2014-06-14
      • 1970-01-01
      • 1970-01-01
      • 2022-09-30
      • 2018-02-17
      • 2016-12-09
      • 1970-01-01
      相关资源
      最近更新 更多