0

I have an output printed that shows 2 variable with "array" in front of them. I am trying to remove these and just make it a normal array so I can convert into a data frame

(array([5.13431118, 2.75188667, 2.14270195, 1.85232761, 1.54816285,
       1.07358247, 0.83953893, 0.79920618, 0.71898919, 0.68808879,
       0.67637336, 0.65179984, 0.62325295, 0.59656284, 0.56309083,
       0.54330533, 0.51451752, 0.49450315, 0.48263952, 0.448921  ,
       0.42336611, 0.40067145, 0.38780448, 0.38185679, 0.26253902]), array([ 4.73899342,  2.39633009,  1.70232176,  1.35374982,  1.10683548,
        0.61925838,  0.38851972,  0.34679717,  0.24324399,  0.23452607,
        0.20272406,  0.16004198,  0.12964943,  0.11750156,  0.09877278,
        0.0909908 ,  0.07669317,  0.05444491,  0.04149164,  0.02239192,
        0.01442321,  0.01144795,  0.00353863,  0.00107867, -0.00000164]))

This works when putting a * in front of the variable when using print function. But can't actually save it.

print('Eigen Values Test(>1.0):',*ev,sep="\n")

Example above my whole code below

#Import required libraries
import numpy as np
import pandas as pd
import scipy
from sklearn.datasets import load_iris
from factor_analyzer import FactorAnalyzer
import matplotlib.pyplot as plt

df = pd.read_csv("https://www.dropbox.com/s/110tmphef00ybyg/bfi.csv?raw=1")

#show existing columns
print(df.columns) 

# Dropping unnecessary columns
df.drop(['gender', 'education', 'age', 'Unnamed: 0'],axis=1,inplace=True)

#Dropping missing values rows
df.dropna(inplace=True) # Removes Entire row that has NA

# Summary of data
print(df.info())
print(df.head())


#ADEQUACY TEST (Testing factorability)

print('')

#Bartlett’s test

from factor_analyzer.factor_analyzer import calculate_bartlett_sphericity
chi_square_value,p_value=calculate_bartlett_sphericity(df)
print('Bartlett’s test:',chi_square_value, p_value,sep='\n')

#Kaiser-Meyer-Olkin (KMO) Test

from factor_analyzer.factor_analyzer import calculate_kmo
kmo_all,kmo_model=calculate_kmo(df)
print('Kaiser-Meyer-Olkin (KMO) Test(>0.8):', kmo_model,sep='\n')

#CHOOSING NUMBER OF FACTORS

# Create factor analysis object and perform factor analysis
fa = FactorAnalyzer(25, rotation=None)

print('')

# Check Eigenvalues
fa.fit(df)
ev = fa.get_eigenvalues()

print('Eigen Values Test(>1.0):',ev,sep="\n")

Ideally it should look like:

[5.13431118 2.75188667 2.14270195 1.85232761 1.54816285 1.07358247
 0.83953893 0.79920618 0.71898919 0.68808879 0.67637336 0.65179984
 0.62325295 0.59656284 0.56309083 0.54330533 0.51451752 0.49450315
 0.48263952 0.448921   0.42336611 0.40067145 0.38780448 0.38185679
 0.26253902]
[ 4.73899342  2.39633009  1.70232176  1.35374982  1.10683548  0.61925838
  0.38851972  0.34679717  0.24324399  0.23452607  0.20272406  0.16004198
  0.12964943  0.11750156  0.09877278  0.0909908   0.07669317  0.05444491
  0.04149164  0.02239192  0.01442321  0.01144795  0.00353863  0.00107867
 -0.00000164]
Barmar
  • 741,623
  • 53
  • 500
  • 612
Mish
  • 51
  • 7
  • 1
    What do you mean by a "normal array"? Python doesn't have built-in arrays, they're a numpy feature. Do you mean you want to convert the numpy array to a list? – Barmar Oct 31 '19 at 03:19
  • I figured it out. I did: # Check Eigenvalues fa.fit(df) ev, v = fa.get_eigenvalues() This then made 2 separate arrays one being "ev" and the other being "v" Then I can use them both separately a when i print them out the "array" does not appear anymore – Mish Oct 31 '19 at 03:42
  • 2
    `array9...]` is the repr display of a numpy array. `array` is omitted with the `str` display. The str also omits the comma. – hpaulj Oct 31 '19 at 04:37
  • 1
    The first display shows a `tuple` of numpy arrays. The second is the two arrays printed separatly. Focus on what the python objects. The display is secondary. Normaly a dataframe (another kind of object) is created from one or more numpy arrays. – hpaulj Oct 31 '19 at 05:01
  • 1
    Using `tolist` to turn an array into a list is not relevant to this question. The OP is confusing the display method(s) and the actual objects. The original structure is a tuple of numpy arrays. – hpaulj Oct 31 '19 at 05:12

0 Answers0