作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道我们只能使用 pandas 数据框过滤器选择几列,但我们也可以只排除一些列吗?
这是MWE:
import numpy as np
import pandas as pd
df = pd.DataFrame({'id': [1,2,3], 'num_1': [10,20,30], 'num_2': [20,30,40]})
df.filter(regex='num')
df.filter(regex='^(num)')
id
0 1
1 2
2 3
# these already works, i am only looking regex way
df[['id']] # gives the required output
最佳答案
您可以获得没有 num
的列的列表使用列表理解
cols_without_num = [x for x in list(df) if 'num' not in x]
df[cols_without_num]
关于python - 如何排除和过滤 Pandas 中的几列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56009504/
我正在尝试使用描述的方法将数据表转换为字典 here , 但我得到一个错误 Cannot implicitly convert type System.Collections.Generic.Dict
我想在几个列上使用 orderBY,但它们应该像一列一样。 该表看起来像这样: col1 | col2 5 | 2 | | 3 7 | | 1 | 1
我有这张表 mytable: +----+--------------------------------------+ | id | date1 | date2 | date3
我是一名优秀的程序员,十分优秀!