# Pandas comprehensive application

2022-01-30 08:46:12

# Homework

## 1. Judge whether the following naming methods are correct （ It is recommended that each run once ）

#  wrong
1name = ' Face value of bonds '
#  Yes
a_ = 12
#  Yes
_ = 123
#  wrong
_\$ = 444
#  Yes
__ = ' Face value of bonds '
#  wrong
123 = 666
#  Yes
a1b = 45
Copy code 
  File "<ipython-input-1-75692b094e3d>", line 2
1name = ' Face value of bonds '
^
SyntaxError: invalid syntax
Copy code 

## 2.F=' Bond's 1 Face value ' Medium 1 Get rid of

 #** Where code needs to be filled in
F=' Bond's 1 Face value '
a=list(F) # The first string Type conversion to list type
# ** # hold 1 Get rid of
a.remove('1')
F=''.join(a) # hold list Turn into string type
print(F)
Copy code 
 Face value of bonds
Copy code 

## 3. Here is a list , Write the answers according to the requirements of each small question and run

a = [' China securities circulation ', ' personal witness 100', ' The Shanghai composite index ',' The Shanghai composite index ', 'Ａ Stock index ', 'B Stock index ' ,' Deep evidence F60', ' The Shanghai composite index ',' Deep evidence F120']

1. Calculate the length of the list and output
2. Append elements to list " Deep evidence F200", And output the added list
3. Please go to No 1 Location insert element " Shanghai and Shenzhen 300", And output the added list
4. Please list b=['000300', '000902', '000903'] Add each element of to the list li in , One line of code , Circular addition is not allowed .
5. Please delete the elements in the list " The Shanghai composite index ", And output the added list
6. Please delete the 2 Elements , And output the deleted element and the list after deleting the element
7. Please delete the 2 to 4 Elements , And output the list after deleting the element
8. Please invert all the elements in the list , And output the inverted list
9. Please calculate "' The Shanghai composite index '," The elements are in the list a Is the number of times , And output the number of times .
a = [' China securities circulation ', ' personal witness 100', ' The Shanghai composite index ',' The Shanghai composite index ', 'Ａ Stock index ', 'B Stock index ' ,' Deep evidence F60', ' The Shanghai composite index ',' Deep evidence F120']
Copy code 
print(len(a))
Copy code 
9
Copy code 
a.append(' Deep evidence F200')
print(a)
Copy code 
[' China securities circulation ', ' personal witness 100', ' The Shanghai composite index ', ' The Shanghai composite index ', 'Ａ Stock index ', 'B Stock index ', ' Deep evidence F60', ' The Shanghai composite index ', ' Deep evidence F120', ' Deep evidence F200']
Copy code 
b=['000300', '000902', '000903']
li=[]
li.extend(b)
print(li)
Copy code 
['000300', '000902', '000903']
Copy code 
a.remove(' The Shanghai composite index ')
print(a)
Copy code 
[' China securities circulation ', ' personal witness 100', ' The Shanghai composite index ', 'Ａ Stock index ', 'B Stock index ', ' Deep evidence F60', ' The Shanghai composite index ', ' Deep evidence F120', ' Deep evidence F200']
Copy code 
a.pop(1)
Copy code 
' personal witness 100'
Copy code 
print(a)
Copy code 
[' China securities circulation ', ' The Shanghai composite index ', 'Ａ Stock index ', 'B Stock index ', ' Deep evidence F60', ' The Shanghai composite index ', ' Deep evidence F120', ' Deep evidence F200']
Copy code 
del(a[1:4])
print(a)
Copy code 
[' China securities circulation ', ' Deep evidence F60', ' The Shanghai composite index ', ' Deep evidence F120', ' Deep evidence F200']
Copy code 

## 4. Define a function to calculate the present value of bonds

ABC The company issued a 10 A one-year bond , The face value is ￥1000, The coupon rate is 8%, Pay the principal when due , Interest is paid at the end of each year . Please calculate the present value of the bond . The present value of the bond = Present value of principal + The present value of interest

Present value of principal = $\frac{F}{\left( 1+r \right)^{T}}$

The present value of interest = $\sum_{T}^{i}{\frac{C\times F}{\left( 1+r \right)^{i}}}$

among ,

• F= Face value of bonds =1000
• C= Bond coupon rate =8%
• T= The number of cycles that occur before the bond matures =10
• r= Annual market rate of return =10%
 #** Where code needs to be filled in
def Count(F, C, T, r): # Pass in the parameter
a = F/(1+r)**T    # Define the calculation method   Present value of principal
i=1
b=0   # Initialize the present value of interest
while i<T: # Define the calculation method   The present value of interest
b = b+C*F/(1+r)**i
i = i + 1
return a+b    # Return the present value of the bond
# Define various parameters
F=1000
C=0.08
T=10
r=0.1
print(F,C,T,r)# Output various parameters
print(Count(F, C, T, r)) # The present value of the output bond
Copy code 
1000 0.08 10 0.1
846.2651947315433
Copy code 

END