机器学习—如何将$12.3转换为数字12.3及习题练习

在这里插入图片描述

》》》import pandas as pd
》》》data=pd.read_csv('E:\PYCHAR\新建文件夹 (2)\chipotle.csv','\t')
》》》t=pd.DataFrame(data)
》》》t.head(10)

   order_id  ...  item_price
0         1  ...      $2.39 
1         1  ...      $3.39 
2         1  ...      $3.39 
3         1  ...      $2.39 
4         2  ...     $16.98 
5         3  ...     $10.98 
6         3  ...      $1.69 
7         4  ...     $11.75 
8         4  ...      $9.25 
9         5  ...      $9.25 
[10 rows x 5 columns]

》》》t.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4622 entries, 0 to 4621
Data columns (total 5 columns):
 #   Column              Non-Null Count  Dtype 
---  ------              --------------  ----- 
 0   order_id            4622 non-null   int64 
 1   quantity            4622 non-null   int64 
 2   item_name           4622 non-null   object
 3   choice_description  3376 non-null   object
 4   item_price          4622 non-null   object
dtypes: int64(2), object(3)
memory usage: 180.7+ KB
》》》t.columns
Index(['order_id', 'quantity', 'item_name', 'choice_description',
       'item_price'],
      dtype='object')
》》》sum(t.order_id * [float(i[1:]) for i in t.item_price])
31973656.510000028

此处为如何将一个带有符号的数字字符转换为数字,比如$12.3转换为12.3
[float(i[1:]) for i in 数组名【¥123.。。】
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值