Python | Панды dataframe.cov ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas dataframe.cov() is used to compute pairwise covariance of columns.
If some of the cells in a column contain NaN value, then it is ignored.
Syntax: DataFrame.cov(min_periods=None)
Parameters:
min_periods : Minimum number of observations required per pair of columns to have a valid result.Returns: y : DataFrame
Example #1: Use cov() function to find the covariance between the columns of the dataframe.
Note : Any non-numeric columns will be ignored.
# importing pandas as pdimport pandas as pd # Creating the dataframedf = pd.DataFrame({"A":[5, 3, 6, 4], "B":[11, 2, 4, 3], "C":[4, 3, 8, 5], "D":[5, 4, 2, 8]}) # Print the dataframedf |
Выход :
Now find the covariance among the columns of the data frame
# To find the covariance df.cov() |
Выход :
Example #2: Use cov() function to find the covariance between the columns of the dataframe which are having NaN value.
# importing pandas as pdimport pandas as pd # Creating the dataframedf = pd.DataFrame({"A":[5, 3, None, 4], "B":[None, 2, 4, 3], "C":[4, 3, 8, 5], "D":[5, 4, 2, None]}) # To find the covariance df.cov() |
Выход :
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.