Python中文
首页
教程
问答
标签
搜索
登录
注册
如何从Pandas数据帧的列表中删除值?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我创建了一个数据帧:</p> <pre><code>[in] testing_df =pd.DataFrame(test_array,columns=['transaction_id','product_id']) # Split the product_id's for the testing data testing_df.set_index(['transaction_id'],inplace=True) testing_df['product_id'] = testing_df['product_id'].apply(lambda row: row.split(',')) [out] product_id transaction_id 001 [P01] 002 [P01, P02] 003 [P01, P02, P09] 004 [P01, P03] 005 [P01, P03, P05] 006 [P01, P03, P07] 007 [P01, P03, P08] 008 [P01, P04] 009 [P01, P04, P05] 010 [P01, P04, P08] </code></pre> <p>现在如何从结果中删除“P04”和“P08”?在</p> <p>我试过了:</p> ^{pr2}$ <p>然而,这两种选择似乎都行不通。在</p> <p>数据类型包括:</p> <pre><code>[in] print(testing_df.dtypes) [out] product_id object dtype: object [in] print(testing_df['product_id'].dtypes) [out] object </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>将要删除的所有元素存储在列表中。在</p> <pre><code>remove_results = ['P04','P08'] for k in range(len(testing_df['product_id'])): for r in remove_results: if r in testing_df['product_id'][k]: testing_df['product_id][k].remove(r) </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将命令集结果作为variab执行
9 回答
将命令馈送到twisted ssh之后反应器.运行()
8 回答
将命名元组列表附加到另一个元组
10 回答
将命名元组的值从字符串转换为整数
4 回答
将命名参数和文件像脚本一样传入和传出docker容器
2 回答
将命名参数打包到di中
3 回答
将命名捕获组替换为re.sub公司
6 回答
将命名空间包添加到事实之后的包中
4 回答
将命名空间添加到Suds中的默认WSSE安全对象
7 回答
将命名范围从Excel导入Python脚本
5 回答
将品脱单位格式化为缩写符号
3 回答
将哈夫曼代码字符串转换为二进制
4 回答
将哈希“#”解析为flask routes中URL请求中的字符串
2 回答
将哈希密码从flask导入Django
4 回答
将哈希密码插入sqlite3表
3 回答
将哈希密码转换为字符串werkuzeug python
2 回答
将哈希打印到fi
1 回答
将哈希模式应用于条形图
10 回答
将哈希模式添加到seaborn条p
8 回答
将哈希码转换为其二进制表示
3 回答