In [1]:
import pandas as pd
In [45]:
df = pd.read_csv('price.csv', sep=';')
df
Out[45]:
id title price
0 1 Ноутбук Acer Aspire 5 A515-54G-502N (NX.HVGEU.... 10$
1 2 Ноутбук Asus ROG Strix G15 G512LI-HN057 (90NR0... 11$
2 3 Ноутбук HP Pavilion Gaming 15-bc504ur (7DT87EA... 7$
3 4 Ноутбук HP Pavilion Notebook 15-cw1011ua (8RW1... 25$
4 5 Ноутбук Acer Aspire 7 A715-41G-R7MZ (NH.Q8LEU.... 35$
5 6 Ноутбук Dell Inspiron 3582 (I3582C54H5NIL-BK) ... 5$
6 7 Ноутбук Apple MacBook Air 13" 256GB 2020 Space... 11$
7 8 Ноутбук Asus ROG Strix G15 G512LI-HN094 (90NR0... 16$
8 9 Ноутбук HP Pavilion Notebook 15-cw1002ua (7KE5... 15$
9 10 Ноутбук HP Pavilion Notebook 15-cw1005ua (7ZF7... 20$
10 11 Ноутбук Lenovo IdeaPad L340-15IRH Gaming (81LK... 10$
In [46]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 11 entries, 0 to 10
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   id      11 non-null     int64 
 1   title   11 non-null     object
 2   price   11 non-null     object
dtypes: int64(1), object(2)
memory usage: 392.0+ bytes
In [47]:
df.dtypes
Out[47]:
id        int64
title    object
price    object
dtype: object
In [48]:
df['price'] = df.price.str.replace('$', '')
In [49]:
df
Out[49]:
id title price
0 1 Ноутбук Acer Aspire 5 A515-54G-502N (NX.HVGEU.... 10
1 2 Ноутбук Asus ROG Strix G15 G512LI-HN057 (90NR0... 11
2 3 Ноутбук HP Pavilion Gaming 15-bc504ur (7DT87EA... 7
3 4 Ноутбук HP Pavilion Notebook 15-cw1011ua (8RW1... 25
4 5 Ноутбук Acer Aspire 7 A715-41G-R7MZ (NH.Q8LEU.... 35
5 6 Ноутбук Dell Inspiron 3582 (I3582C54H5NIL-BK) ... 5
6 7 Ноутбук Apple MacBook Air 13" 256GB 2020 Space... 11
7 8 Ноутбук Asus ROG Strix G15 G512LI-HN094 (90NR0... 16
8 9 Ноутбук HP Pavilion Notebook 15-cw1002ua (7KE5... 15
9 10 Ноутбук HP Pavilion Notebook 15-cw1005ua (7ZF7... 20
10 11 Ноутбук Lenovo IdeaPad L340-15IRH Gaming (81LK... 10
In [33]:
df['price'] = df.price.astype('float')
In [50]:
df.dtypes
Out[50]:
id        int64
title    object
price    object
dtype: object
In [56]:
pd.to_numeric(df.price)
Out[56]:
0     10
1     11
2      7
3     25
4     35
5      5
6     11
7     16
8     15
9     20
10    10
Name: price, dtype: int64
In [ ]:
 
In [83]:
df['price'] = df.price.astype('uint8')
In [84]:
df.dtypes
Out[84]:
id        int64
title    object
price     uint8
dtype: object
In [92]:
df.loc[11] = [12, 'Test', 257]
In [93]:
df
Out[93]:
id title price
0 1 Ноутбук Acer Aspire 5 A515-54G-502N (NX.HVGEU.... 10
1 2 Ноутбук Asus ROG Strix G15 G512LI-HN057 (90NR0... 11
2 3 Ноутбук HP Pavilion Gaming 15-bc504ur (7DT87EA... 7
3 4 Ноутбук HP Pavilion Notebook 15-cw1011ua (8RW1... 25
4 5 Ноутбук Acer Aspire 7 A715-41G-R7MZ (NH.Q8LEU.... 35
5 6 Ноутбук Dell Inspiron 3582 (I3582C54H5NIL-BK) ... 5
6 7 Ноутбук Apple MacBook Air 13" 256GB 2020 Space... 11
7 8 Ноутбук Asus ROG Strix G15 G512LI-HN094 (90NR0... 16
8 9 Ноутбук HP Pavilion Notebook 15-cw1002ua (7KE5... 15
9 10 Ноутбук HP Pavilion Notebook 15-cw1005ua (7ZF7... 20
10 11 Ноутбук Lenovo IdeaPad L340-15IRH Gaming (81LK... 10
11 12 Test 1
In [87]:
df.dtypes
Out[87]:
id        int64
title    object
price     uint8
dtype: object
In [94]:
import numpy as np
In [95]:
np.iinfo(df.price)
Out[95]:
iinfo(min=0, max=255, dtype=uint8)
In [100]:
df['price'] = df.price.astype('uint32')
In [101]:
np.iinfo(df.price)
Out[101]:
iinfo(min=0, max=4294967295, dtype=uint32)
In [103]:
df.price.sum()
Out[103]:
166
In [ ]: