Program to convert a NumPy array to a Pandas series.

In this python pandas program, we will convert a NumPy array to a Pandas series.

Steps to solve the program
  1. Import pandas library as pd.
  2. Import NumPy library as np.
  3. Create a NumPy array using np.array().
  4. Now convert that array to a Pandas series using pd.Series().
  5. Print the output.
				
					import numpy as np
import pandas as pd
array = np.array([5,3,8,9,0])
result = pd.Series(array)
print(result)
				
			

Output :

				
					0    5
1    3
2    8
3    9
4    0
dtype: int32
				
			

convert a dictionary to a series

change the data type of given a column or a Series

Program to convert a dictionary to a Pandas series.

In this python pandas program, we will convert a dictionary to a Pandas series.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create a dictionary.
  3. Now convert that dictionary to a series using pd.Series().
  4. Print the output.
				
					import pandas as pd
D = {'name':'Virat','sport':'cricket','age':32}
result = pd.Series(D)
print(result)
				
			

Output :

				
					name       Virat
sport    cricket
age           32
dtype: object
				
			

check whether elements in the series are greater than other series

convert a NumPy array to a Pandas series

Check whether elements in the series are greater than other series

In this python pandas program, we will elements in the series are greater than other series.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create two series using pd.Series().
  3. Check whether elements in the series are greater than other series or not using ” > “.
  4. Print the output.
				
					import pandas as pd
df1 = pd.Series([1,6,9,5])
df2 = pd.Series([5,2,4,5])
print("Greater than:")
print(df1 > df2)
				
			

Output :

				
					Greater than:
0    False
1     True
2     True
3    False
dtype: bool
				
			

check whether elements in the series are equal or not

convert a dictionary to a series

Check whether elements in the series are equal or not

In this python pandas program, we will check whether elements in the series are equal or not.

Steps to solve the program
  1. Import pandas library as pd.
  2. Create two series using pd.Series().
  3. Check whether elements in the series are equal or not using ” == “.
  4. Print the output.
				
					import pandas as pd
df1 = pd.Series([1,6,9,5])
df2 = pd.Series([5,2,4,5])
print("Equals:")
print(df1 == df2)
				
			

Output :

				
					Equals:
0    False
1    False
2    False
3     True
dtype: bool
				
			

divide two series

check whether elements in the series are greater than other series

Program to divide two series

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

Steps to solve the program
  1. Import pandas library as pd.
  2. Create two series using pd.Series().
  3. Now divide 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    0.20
1    3.00
2    2.25
3    1.00
dtype: float64
				
			

multiply two series

check whether elements in the series are equal or not

Program to multiply two series

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

Steps to solve the program
  1. Import pandas library as pd.
  2. Create two series using pd.Series().
  3. Now multiply 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     5
1    12
2    36
3    25
dtype: int64
				
			

subtract two series

divide two series

Program to subtract two series

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

Steps to solve the program
  1. Import pandas library as pd.
  2. Create two series using pd.Series().
  3. Now subtract 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   -4
1    4
2    5
3    0
dtype: int64
				
			

add two series

multiply two series

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