https://www.online-python.com/lH6xbUhOIA
# code :
https://www.online-python.com/lH6xbUhOIA
import pandas as pd
from pandas import Timestamp
vol = pd.DataFrame({'item': {1: 'S043693',
2: 'S065561',
3: 'S055150',
4: 'S065492',
5: 'S065492',
78455: 'S005309',
78456: 'S029730',
78457: 'S005306',
78458: 'S037183',
78459: 'S005306'},
'period': {1: Timestamp('2022-04-15 00:00:00'),
2: Timestamp('2022-12-15 00:00:00'),
3: Timestamp('2022-04-15 00:00:00'),
4: Timestamp('2022-06-15 00:00:00'),
5: Timestamp('2022-03-15 00:00:00'),
78455: Timestamp('2022-01-15 00:00:00'),
78456: Timestamp('2022-01-15 00:00:00'),
78457: Timestamp('2022-01-15 00:00:00'),
78458: Timestamp('2022-01-15 00:00:00'),
78459: Timestamp('2022-01-15 00:00:00')},
'sales_qty': {1: ' 1,371 ',
2: ' 958 ',
3: ' 1,171 ',
4: ' 311 ',
5: ' 460 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '},
'gross_sales': {1: ' 1,491,011 ',
2: ' 7,103,719 ',
3: ' 919,137 ',
4: ' 759,777 ',
5: ' 1,140,900 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '},
'net_sales': {1: ' 1,468,976 ',
2: ' 6,998,738 ',
3: ' 905,554 ',
4: ' 748,549 ',
5: ' 1,124,039 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '},
'sales_weight_kg': {1: ' 16,238 ',
2: ' 85,515 ',
3: ' 10,677 ',
4: ' 9,692 ',
5: ' 14,335 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '}})
#print(vol.info())
vol['net_sale_per_pcs'] = 0
vol['net_sale_per_pcs'].apply(lambda a , b: [a/b if b>0 else 0 for a, b in zip(vol['net_sales'],vol['sales_qty'])])
print(vol)
**Error message**
TypeError: <lambda>
) missing 1 required positional argument: 'b'
ผมเจอ error อันนี้
vol['net_sale_per_pcs'].apply(lambda a , b: [a/b if b>0 else 0 for a, b in zip(vol['net_sales'],vol['sales_qty'])])
**Error message**
TypeError: <lambda>
) missing 1 required positional argument: 'b'
รบกวนถามว่าแก้อย่างไรครับ ขอบคุณครับ
python เพื่อหาค่าเฉลี่ยต่อชิ้น แต่ดันเป็น str
https://www.online-python.com/lH6xbUhOIA
# code : https://www.online-python.com/lH6xbUhOIA
import pandas as pd
from pandas import Timestamp
vol = pd.DataFrame({'item': {1: 'S043693',
2: 'S065561',
3: 'S055150',
4: 'S065492',
5: 'S065492',
78455: 'S005309',
78456: 'S029730',
78457: 'S005306',
78458: 'S037183',
78459: 'S005306'},
'period': {1: Timestamp('2022-04-15 00:00:00'),
2: Timestamp('2022-12-15 00:00:00'),
3: Timestamp('2022-04-15 00:00:00'),
4: Timestamp('2022-06-15 00:00:00'),
5: Timestamp('2022-03-15 00:00:00'),
78455: Timestamp('2022-01-15 00:00:00'),
78456: Timestamp('2022-01-15 00:00:00'),
78457: Timestamp('2022-01-15 00:00:00'),
78458: Timestamp('2022-01-15 00:00:00'),
78459: Timestamp('2022-01-15 00:00:00')},
'sales_qty': {1: ' 1,371 ',
2: ' 958 ',
3: ' 1,171 ',
4: ' 311 ',
5: ' 460 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '},
'gross_sales': {1: ' 1,491,011 ',
2: ' 7,103,719 ',
3: ' 919,137 ',
4: ' 759,777 ',
5: ' 1,140,900 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '},
'net_sales': {1: ' 1,468,976 ',
2: ' 6,998,738 ',
3: ' 905,554 ',
4: ' 748,549 ',
5: ' 1,124,039 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '},
'sales_weight_kg': {1: ' 16,238 ',
2: ' 85,515 ',
3: ' 10,677 ',
4: ' 9,692 ',
5: ' 14,335 ',
78455: ' - ',
78456: ' - ',
78457: ' - ',
78458: ' - ',
78459: ' - '}})
#print(vol.info())
vol['net_sale_per_pcs'] = 0
vol['net_sale_per_pcs'].apply(lambda a , b: [a/b if b>0 else 0 for a, b in zip(vol['net_sales'],vol['sales_qty'])])
print(vol)
**Error message**
TypeError: <lambda>) missing 1 required positional argument: 'b'
ผมเจอ error อันนี้
vol['net_sale_per_pcs'].apply(lambda a , b: [a/b if b>0 else 0 for a, b in zip(vol['net_sales'],vol['sales_qty'])])
**Error message**
TypeError: <lambda>) missing 1 required positional argument: 'b'
รบกวนถามว่าแก้อย่างไรครับ ขอบคุณครับ