Program to add two series

In this python pandas program, we will add two series using pandas.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create two series using pd.Series().
  3. Now add the two series using the” + ” operator.
  4. Print the output.
				
					import pandas as pd
df1 = pd.Series([1,6,9,5])
df2 = pd.Series([5,2,4,5])
print(df1+df2)
				
			

Output :

				
					0     6
1     8
2    13
3    10
dtype: int64
				
			

convert a series to a list and print its type

subtract two series

Convert a Pandas series to a list and print its type

In this python pandas program, we will convert a Pandas series to a list and print its type.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a pandas series using pd.Series() and print it.
  3. Now, convert the series to a list using tolist().
  4. To print the type use type().
				
					import pandas as pd
df = pd.Series([15,43,88,23])
print(df)
print(type(df))
print("Convert Pandas Series to Python list")
print(df.tolist())
print(type(df.tolist()))
				
			

Output :

				
					0    15
1    43
2    88
3    23
dtype: int64
<class 'pandas.core.series.Series'>
Convert Pandas Series to Python list
[15, 43, 88, 23]
<class 'list'>
				
			

create and display a one-dimensional array-like object containing an array of data

add two series

Program to create an array using dtype as complex

In this python numpy program, we will create an array using dtype as complex.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array() and set dtype = complex.
  3. It will create an array of complex numbers.
  4. Print the output.
				
					import numpy as np
a = np.array([5,4], dtype = complex)

print(a)
				
			

Output :

				
					[5.+0.j 4.+0.j]
				
			

convert a tuple into an array.

Program to convert a tuple into a NumPy array

In this python numpy program, we will convert a tuple into a NumPy array.

Steps to solve the program
  1. Import the numpy library as np.
  2. Convert a tuple into an array using np.asarray().
  3. Print the output.
				
					import numpy as np
x = np.asarray((5,7,0))

print(x)
				
			

Output :

				
					[5 7 0]
				
			

round off the elements in an array using ceil function.

create an array using dtype as complex.

Program to round off the elements in an array using ceil function

In this python numpy program, we will round off the elements in an array using ceil function.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Round off the elements in an array using np.ceil().
  4. It will round up a decimal number to the next value i.e 12.5 will be 13.
  5. Print the output.

				
					import numpy as np
arr = np.array([12.202, 90.23120, 123.88, 23.202])  

print(np.ceil(arr)
				
			

Output :

				
					[ 13.  91. 124.  24.]
				
			

round off the elements in an array using the floor function.

convert a tuple into an array.

Program to round off the elements in an array using the floor function

In this python numpy program, we will round off the elements in an array using the floor function.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Round off the elements in an array using np.floor().
  4. It will round up a decimal number to its base value i.e 12.5 will be 12.
  5. Print the output.
				
					import numpy as np
arr = np.array([12.202, 90.23120, 123.88, 23.202])

print(np.floor(arr))
				
			

Output :

				
					[ 12.  90. 123.  23.]
				
			

round off the elements in an array up to two digits.

round off the elements in an array using ceil function.

Program to round off the elements in an array up to two digits

In this python numpy program, we will round off the elements in an array up to two digits.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Round off the elements in an array up to two digits using np.round().
  4. Print the output.
				
					import numpy as np
arr = np.array([12.202, 90.23120, 123.88, 23.202])  

print(np.round(arr,2))
				
			

Output :

				
					[ 12.2   90.23 123.88  23.2 ]
				
			

calculate the tan angle of an array.

round off the elements in an array using the floor function.

Calculate the tan angle of an array using NumPy

In this python numpy program, we will calculate the tan angle of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the tan angle of the array using np.tan().
  4. Print the output.
				
					import numpy as np
angle = np.array([45,13])

print(f"Tan of {angle}: ",np.tan(angle))
				
			

Output :

				
					Tan of [45 13]:  [1.61977519 0.46302113]
				
			

calculate the cos angle of an array.

round off the elements in an array up to two digits.

Calculate the cos angle of an array using NumPy

In this python numpy program, we will calculate the cos angle of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Calculate the cos angle of the array using np.cos().
  4. Print the output.
				
					import numpy as np
angle = np.array([45,13])

print(f"Cos of {angle}: ",np.cos(angle))
				
			

Output :

				
					Cos of [45 13]:  [0.52532199 0.90744678]
				
			

calculate the variance of an array.

calculate the tan angle of an array.