》》》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):
--- ------ -------------- -----
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 数组名【¥12,3.。。】