I'm trying to download fundamental data from Yahoo Finance like PE ratios, PB ratios, EV/EBITDA, etc. This is what I've done so far:
#import required libraries
import pandas as pd
import numpy as np
import requests
import xlsxwriter
from scipy import stats
import math
import secrets
import yfinance as yf
import matplotlib.pyplot as plt
import datetime as dt
import statsmodels.api as sm
pip install requests_html
stocks = pd.read_csv('constituents.csv')
from yahoo_fin.stock_info import get_data
sm.get_stats_valuation("aapl")
I get this error:
AttributeError Traceback (most recent call last)
<ipython-input-17-7a641ee9069d> in <module>
----> 1 sm.get_stats_valuation("aapl")
AttributeError: module 'statsmodels.api' has no attribute 'get_stats_valuation'
What do I do?
I checked the website you specified in comment. I think you can get stats valuation from stock_info module itself of the yahoo_fin package. Please check:
import yahoo_fin.stock_info as si
si.get_stats_valuation("aapl")
Related
I learned a lot of solutions from this website, but still cannot solve the problem. My code is as follows for your review:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import missingno as msno
import altair as alt
from statsmodels.graphics.mosaicplot import mosaic
from scipy.stats import chi2_contingency
import plotly.express as px
from pandas.plotting import parallel_coordinates
from wordcloud import WordCloud
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
from scipy.spatial import distance
!pip install sklearn
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
from sklearn.impute import KNNImputer
from missingpy import MissForest
import sklearn.neighbors._base
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
import warnings
warnings.filterwarnings("ignore")
And still shows the error: ModuleNotFoundError: No module named 'sklearn.neighbors.base' I've tried to do the follows:
pip install -U imbalanced-learn ;
pip install -U scikit-learn
ans there was still of no use
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11280/2643854484.py in <module>
26 from sklearn.impute import IterativeImputer
27 from sklearn.impute import KNNImputer
---> 28 from missingpy import MissForest
29 import sklearn.neighbors._base
30 sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
C:\ProgramData\Anaconda3\lib\site-packages\missingpy\__init__.py in <module>
----> 1 from .knnimpute import KNNImputer
2 from .missforest import MissForest
3
4 __all__ = ['KNNImputer', 'MissForest']
C:\ProgramData\Anaconda3\lib\site-packages\missingpy\knnimpute.py in <module>
11 from sklearn.utils.validation import check_is_fitted
12 from sklearn.utils.validation import FLOAT_DTYPES
---> 13 from sklearn.neighbors.base import _check_weights
14 from sklearn.neighbors.base import _get_weights
15
ModuleNotFoundError: No module named 'sklearn.neighbors.base'
Finally, I solved the problem!!
I should write this before import missingpy, not behind it.
import sklearn.neighbors._base
import sys
sys.modules['sklearn.neighbors.base'] = sklearn.neighbors._base
from missingpy import MissForest
done.
Okay, so I am currently working on a project using Jupyter Notebook and had to create colormaped representations of USA counties, thus I realised that I need to install geopandas to proceed further.
So, on the mac terminal I wrote
pip install geopandas
and it installed v 0.10.2 for me.
But now when I am doing the following:
import geopandas
in notebook, it gives me this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-90-2ba400db65f5> in <module>
23 import xlrd
24 import plotly.figure_factory as ff
---> 25 import geopandas.plotting
~/opt/anaconda3/lib/python3.8/site-packages/geopandas/__init__.py in <module>
2
3 from geopandas.geoseries import GeoSeries # noqa
----> 4 from geopandas.geodataframe import GeoDataFrame # noqa
5 from geopandas.array import points_from_xy # noqa
6
~/opt/anaconda3/lib/python3.8/site-packages/geopandas/geodataframe.py in <module>
62
63
---> 64 class GeoDataFrame(GeoPandasBase, DataFrame):
65 """
66 A GeoDataFrame object is a pandas.DataFrame that has a column
~/opt/anaconda3/lib/python3.8/site-packages/geopandas/geodataframe.py in GeoDataFrame()
1851 return self.geometry.difference(other)
1852
-> 1853 plot = CachedAccessor("plot", geopandas.plotting.GeoplotAccessor)
1854
1855 #doc(_explore)
AttributeError: partially initialized module 'geopandas' has no attribute 'plotting' (most likely due to a circular import)
The complete block of code which is getting executed is as follows:
import pandas as pd
pd.options.mode.chained_assignment = None # default='warn'
import opendatasets as od
import plotly.express as px
import plotly.graph_objs as go
from plotly.offline import iplot
import seaborn as sns
import re
from plotly.offline import init_notebook_mode
init_notebook_mode(connected=True)
from wordcloud import WordCloud
from math import pi
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
from tqdm import tqdm
import shapely
import shapefile
import xlrd
import plotly.figure_factory as ff
import geopandas
Kindly explain how can I solve this error and proceed further. I have tried all from my side for couple of hours.
What exactly is this 'most likely due to a circular import'? How to resolve it?
I'm currently having trouble importing some simple packages.
I'm working on pycharm professional in a virtual environment.
just trying to load;
import pandas as pd
import numpy as np
from sklearn.ensemble import IsolationForest
from sklearn.ensemble._iforest import _average_path_length
import shap
importError Traceback (most recent call last)
<ipython-input-1-5b7f1bf909af> in <module>
----> 1 import pandas as pd
2 import numpy as np
3 from sklearn.ensemble import IsolationForest
4 from sklearn.ensemble._iforest import _average_path_length
5 import shap
~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pandas\__init__.py in <module>
14
15 if missing_dependencies:
---> 16 raise ImportError(
17 "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
18 )
ImportError: Unable to import required dependencies:
numpy: cannot import name 'asanyarray' from 'numpy.core.multiarray' (C:\Users\James\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\numpy\core\multiarray.py
I've never come across this error before so don't know how to fix.
I had a problem running my http://127.0.0.1:5000/iris/1/1/1/1. It keeps getting an internal server error. I don't know why and It kept doing it. I tried many ways but it still didn't work. Its kept saying "modulenotfounderror: no module named 'sklearn.linear_model.logistic' ." Is there a way to resolve this.
from flask import Flask, render_template
from flask import jsonify
from datetime import datetime
import numpy as np
import pandas as pd
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression
from mpl_toolkits import mplot3d
from sklearn.datasets import load_iris
from sklearn import datasets
import csv
import joblib
app = Flask(__name__)
def predict(sepal_length, sepal_width, petal_length, petal_width):
test_data = np.array([sepal_length, sepal_width, petal_length,petal_width])
test_data = test_data.reshape(1,-1)
file = open("data/iris.pkl","rb")
trained_model = joblib.load(file)
prediction = trained_model.predict(test_data)
return prediction
#app.route("/iris/<sepal_length>/<sepal_width>/<petal_length>/<petal_width>")
def iris(sepal_length, sepal_width, petal_length, petal_width):
result=predict(np.double(sepal_length),
np.double(sepal_width),
np.double(petal_length),
np.double(petal_width))
if result[0]==0:
hasil='Setosa'
elif result[0]==1:
hasil='Versicolor'
else:
hasil='Virginica'
return hasil
Check the version of scikit-learn, maybe it is 0.21.x. upgrade the version.
Here is scikit-learn stable:
https://github.com/scikit-learn/scikit-learn/tree/master/sklearn/linear_model
In Ubuntu 14.04, I have installed Graphlab based on https://dato.com/download/install-graphlab-create-command-line.html and it seems to be working fine.
However, I receive this error when trying to use a recommender module:
import graphlab
from graphlab.recommender import ranking_factorization_recommender
In the first line, graphlab is imported without any error. However, the second line causes this error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-34df81ffb957> in <module>()
----> 1 from graphlab.recommender import ranking_factorization_recommender
ImportError: No module named recommender
How can the problem be solved? Thanks
It's just a namespace issue. recommender actually lives in the `toolkits module, so this should work:
import graphlab
from graphlab.toolkits.recommender import ranking_factorization_recommender
Graphlab has already imported everything for you in their __init__.py file.
Just do:
from graphlab import ranking_factorization_recommender
from graphlab import <any_other_recommender>
Here is a snippet of graphlab.__init__.py file:
from graphlab.util import get_runtime_config
from graphlab.util import set_runtime_config
import graphlab.connect as _mt
import graphlab.connect.aws as aws
from . import visualization
import os as _os
import sys as _sys
if _sys.platform != 'win32' or \
(_os.path.exists(_os.path.join(_os.path.dirname(__file__), 'cython', 'libstdc++-6.dll')) and \
_os.path.exists(_os.path.join(_os.path.dirname(__file__), 'cython', 'libgcc_s_seh-1.dll'))):
from graphlab.data_structures.sgraph import Vertex, Edge
from graphlab.data_structures.sgraph import SGraph
from graphlab.data_structures.sarray import SArray
from graphlab.data_structures.sframe import SFrame
from graphlab.data_structures.sketch import Sketch
from graphlab.data_structures.image import Image
from graphlab.data_structures.sgraph import load_sgraph, load_graph
from graphlab.toolkits._model import Model, CustomModel
import graphlab.aggregate
import graphlab.toolkits
import graphlab.toolkits.clustering as clustering
import graphlab.toolkits.distances as distances
...