Python中文
首页
教程
问答
标签
搜索
登录
注册
Pandas:如何获取除与给定列表匹配的列名之外的列名
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<div> </div> <p>假设我有一个df:</p> <pre><code>df = pd.DataFrame({'day': range(1, 4), 'apple': range(5, 8), 'orange': range(7, 10), 'pear': range(9, 12), 'purchase': [1, 1, 1], 'cost': [50, 55, 60]}) day apple orange pear purchase cost 1 5 7 9 1 50 2 6 8 10 1 55 3 7 9 11 1 60 </code></pre> <p>如何获取所有列名,但排除名称与<code>day</code>、<code>purchase</code>、&<code>cost</code></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>通过列表理解</p> <pre><code>cols = [i for i in df.columns if i not in ["day", "purchase", "cost"]] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
9 回答
如何在python中从数据帧列表中删除引号
6 回答
如何在python中从数据帧创建列表
2 回答
如何在Python中从数据帧创建嵌套的JSON
10 回答
如何在Python中从数据帧显示wordcloud
2 回答
如何在Python中从数据帧的时间戳中删除字符
6 回答
如何在Python中从数据帧绘制简单绘图?
6 回答
如何在python中从数据帧行提取具有特定长度的范围?
7 回答
如何在python中从数据帧设置dict中的值
8 回答
如何在Python中从数据库中获得一个结果
7 回答
如何在python中从数据框中绘制分类条形图
8 回答
如何在Python中从数据框中选择特定细节?
5 回答
如何在python中从数据集中删除unicode
2 回答
如何在python中从数据集中删除某些数值?
6 回答
如何在python中从数据集中选择行
10 回答
如何在Python中从数组中删除元素
4 回答
如何在python中从数组中删除单个倒逗号?
7 回答
如何在python中从数组中删除对象?
3 回答
如何在python中从数组中删除引号
9 回答
如何在python中从数组中删除所有最小值
10 回答