string - pandas:获取带有字符串数字的列表的最大值
问题描述
我有一个数据框df=pd.DataFrame({'xx':[['100','5','3'], ['5','40'], ['100']]})
,我想将每个列表的最大值作为一个数字。所以我想得到这个:
xx
0 100
1 40
2 100
有没有办法做到这一点?
解决方案
将值转换为整数并获取max
值:
df['xx'] = df['xx'].map(lambda x: max(int(y) for y in x))
或使用列表理解:
df['xx'] = [max(int(y) for y in x) for x in df['xx']]
print(df)
xx
0 100
1 40
2 100
推荐阅读
- spring-boot - Spring Boot 通过外部属性禁用 @JmsListener
- c# - 使用异步/等待时的互斥应用程序异常
- javascript - Rails 中的 React:在 Reflux Store 中更新 Props 不会导致组件更新
- node.js - npm 错误!无效的包名称“__init__.py”:名称不能以下划线开头
- python - 有什么方法可以增加我的哈希的冲突次数以进行音频处理吗?
- c# - chttp2_server.cc:298:断言失败:*port_num == port_temp 在同一台机器上运行服务器和客户端时(仅在 Citrix 上)
- flutter - 以本机设备分辨率显示图像
- sql - 仅从行中获取数字并对所有行求和的问题
- angular - 通过firebase在firebase上上传多个图像时出现问题
- python - cuPy 错误:不允许通过 __array__ 隐式转换为主机 NumPy 数组,