欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pandas計(jì)算相關(guān)系數(shù)corr返回空的問(wèn)題解決

 更新時(shí)間:2023年01月17日 09:56:30   作者:呆萌的代Ma  
本文主要介紹了pandas計(jì)算相關(guān)系數(shù)corr返回空的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

解決方法

查看dataframe的數(shù)據(jù)類型,轉(zhuǎn)為數(shù)值類型即可:

dataframe = dataframe.astype("float")

或者逐列轉(zhuǎn)換:

for _i, _value in dataframe.iteritems():
    dataframe.loc[:, _i] = pd.to_numeric(_value)

問(wèn)題復(fù)現(xiàn)

import pandas as pd
import numpy as np

dataframe = pd.DataFrame(np.random.random(size=(10, 5)))

這時(shí)計(jì)算.corr()會(huì)得到預(yù)期的結(jié)果:

在這里插入圖片描述

但如果轉(zhuǎn)為object類型就會(huì)變?yōu)榭罩担?/p>

在這里插入圖片描述

此時(shí)的dataframe.info()得到的結(jié)果為:

RangeIndex: 10 entries, 0 to 9
Data columns (total 5 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   0       10 non-null     object
 1   1       10 non-null     object
 2   2       10 non-null     object
 3   3       10 non-null     object
 4   4       10 non-null     object
dtypes: object(5)
memory usage: 528.0+ bytes

到此這篇關(guān)于pandas計(jì)算相關(guān)系數(shù)corr返回空的問(wèn)題解決的文章就介紹到這了,更多相關(guān)pandas corr返回空內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論