在 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()找出任何列的指数 函数。此函数计算输入数组/系列的指数。
Syntax: numpy.exp(array, out = None, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None)
Return: An array with exponential of all elements of input array/Series.
示例 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
输出:
示例 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
输出: