20. Consider the following DataFrame
saleDf
|
Target |
Sales |
ZoneA |
56000 |
58000 |
ZoneB |
70000 |
68000 |
ZoneC |
75000 |
78000 |
ZoneD |
60000 |
61000 |
WAP a program to add a column namely
Orders having values 6000, 6700, 6200 and 6000 respectively for the zones A, B,
C and D. The program should also add a new row for a new zone ZoneE. Add some
dummy values in this row.
d={'Target':{'ZoneA':56000,'ZoneB':70000,'ZoneC':75000,'ZoneD':60000},
\
'Sales':
{'ZoneA':58000,'ZoneB':68000,'ZoneC':78000,'ZoneD':61000}}
saleDf=pd.DataFrame(d)
print("DataFrame:
")
print(saleDf)
saleDf['Orders']=[6000, 6700,
6200 , 6000]
saleDf.at['ZoneE',:]=[70000,58000,6100]
print("Updated
DataFrame: ")
print(saleDf)
>>>
======================= RESTART:
C:/Program Files (x86)/Python38-32/IP-20.py ======================
DataFrame:
Target
Sales
ZoneA 56000 58000
ZoneB 70000
68000
ZoneC 75000
78000
ZoneD 60000
61000
Updated DataFrame:
Target Sales
Orders
ZoneA 56000.0
58000.0 6000.0
ZoneB 70000.0
68000.0 6700.0
ZoneC 75000.0
78000.0 6200.0
ZoneD 60000.0
61000.0 6000.0
ZoneE 70000.0
58000.0 6100.0
>>>
No comments:
Post a Comment