📜  在 Pandas-Python 中查找列的指数

📅  最后修改于: 2022-05-13 01:55:51.819000             🧑  作者: Mango

在 Pandas-Python 中查找列的指数

让我们看看如何在 Pandas Dataframe 中找到列的指数。首先,让我们创建一个数据框:

Python3
# importing pandas and
# numpy libraries
import pandas as pd
import numpy as np
  
# creating and initializing a list
values= [ ['Rohan', 5, 50.59], ['Elvish', 2, 90.57],
         ['Deepak', 10, 98.51], ['Soni', 4, 40.24],
         ['Radhika', 1, 99.05], ['Vansh', 15, 85.56] ]
 
# creating a pandas dataframe
df = pd.DataFrame(values, columns = ['Name',
                                     'University_Rank',
                                     'University_Marks'])
 
# displaying the data frame
df


Python3
# importing pandas and
# numpy libraries
import pandas as pd
import numpy as np
  
# creating and initializing a list
values= [ ['Rohan', 5, 50.59], ['Elvish', 2, 90.57],
         ['Deepak', 10, 98.51], ['Soni', 4, 40.24],
         ['Radhika', 1, 99.05], ['Vansh', 15, 85.56] ]
 
# creating a pandas dataframe
df = pd.DataFrame(values, columns = ['Name',
                                     'University_Rank',
                                     'University_Marks'])
 
# finding the exponential value
# of column using np.exp() function
df['exp_value'] = np.exp(df['University_Rank'])
 
# displaying the data frame
df


Python3
# importing pandas and
# numpy libraries
import pandas as pd
import numpy as np
  
# creating and initializing a list
values= [ ['Rohan', 5, 50.59], ['Elvish', 2, 90.57],
         ['Deepak', 10, 98.51], ['Soni', 4, 40.24],
         ['Radhika', 1, 99.05], ['Vansh', 15, 85.56] ]
 
# creating a pandas dataframe
df = pd.DataFrame(values, columns = ['Name',
                                     'University_Rank',
                                     'University_Marks'])
 
# finding the exponential value
# of column  using np.exp() function
df['exp_value'] = np.exp(df['University_Marks'])
 
# displaying the data frame
df


输出:

数据框

使用numpy.exp()找出任何列的指数 函数。此函数计算输入数组/系列的指数。

示例 1:查找单列的指数(整数值)。

Python3

# importing pandas and
# numpy libraries
import pandas as pd
import numpy as np
  
# creating and initializing a list
values= [ ['Rohan', 5, 50.59], ['Elvish', 2, 90.57],
         ['Deepak', 10, 98.51], ['Soni', 4, 40.24],
         ['Radhika', 1, 99.05], ['Vansh', 15, 85.56] ]
 
# creating a pandas dataframe
df = pd.DataFrame(values, columns = ['Name',
                                     'University_Rank',
                                     'University_Marks'])
 
# finding the exponential value
# of column using np.exp() function
df['exp_value'] = np.exp(df['University_Rank'])
 
# displaying the data frame
df

输出:

计算 University_Rank 的指数值

示例 2:查找单列的指数(浮点值)。

Python3

# importing pandas and
# numpy libraries
import pandas as pd
import numpy as np
  
# creating and initializing a list
values= [ ['Rohan', 5, 50.59], ['Elvish', 2, 90.57],
         ['Deepak', 10, 98.51], ['Soni', 4, 40.24],
         ['Radhika', 1, 99.05], ['Vansh', 15, 85.56] ]
 
# creating a pandas dataframe
df = pd.DataFrame(values, columns = ['Name',
                                     'University_Rank',
                                     'University_Marks'])
 
# finding the exponential value
# of column  using np.exp() function
df['exp_value'] = np.exp(df['University_Marks'])
 
# displaying the data frame
df

输出:

计算 University_Marks 的指数值