I am trying to get data from yahoo of stocks of a company through the code.
But i am getting an ImportError at pandas_datareader.data where is says
ImportError: cannot import name 'StringIO'
Please help
I am new to this...and already spent 4 hrs but could not resolve.
I have even tried
import io
from io import StringIO
still getting the same error..!!
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2018,1,1)
end = dt.datetime(2018,12,31)
df = web.datareader('TSLA','yahoo',start,end)
print(df.head(5))
Error:-
Traceback (most recent call last):
File "C:\Users\JAILANCHAL\Desktop\tut.py", line 5, in <module>
import pandas_datareader.data as web
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.av.forex import AVForexReader
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
from pandas_datareader.base import _BaseReader
File "C:\Users\JAILANCHAL\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas_datareader\base.py", line 11, in <module>
from pandas.compat import StringIO, bytes_to_str
ImportError: cannot import name 'StringIO'
Related
Problem
I have written a code that takes some historical data as input. Assuming dataset has a timeseries format, I am trying to do a regression and find a predictor.
Code
For my project, I have four files: my_project.py, utilities.py, plotter.py, and constants.py. Here is some small portions (relevant imports) of the two scripts:
my_project.py:
from time import perf_counter
from constants import (output_dir, DATAPATH, output_file)
from utilities import (dataframe_in_nutshell, excel_reader, info_printer, sys, module_creator, process_discovery, data_explanatory_analysis, excel_reader, df_cleaner, feature_extractor, ml_modelling)
from plotter import Plotter
utilities.py
import os
import sys
import inspect
from pathlib import Path
from typing import (Iterable, List, Tuple, Optional)
from itertools import zip_longest
import matplotlib.pyplot as plt
import statsmodels.tsa.api as smt
import statsmodels.api as sm
import pandas as pd
from sklearn.metrics import mean_absolute_error
from sklearn.preprocessing import scale
from pycaret.regression import (setup, compare_models, predict_model, plot_model, finalize_model, load_model)
import csv
from constants import (np, Path, nan_value, plots_dir, HOURS_PER_WEEK, LAGS_STEP_NUM, rc_params, NA_VALUES, COLUMNS_NAMES, string_columns, LAGS_LABELS, numeric_columns, output_dir, DATAPATH, dtype_dict, train_size)
from pprint import PrettyPrinter
pp = PrettyPrinter()
import seaborn as sns
sns.set()
Error Message
Traceback (most recent call last):
File "c:\Users\username\OneDrive\Desktop\project\my_project.py", line 10, in <module>
from utilities import (dataframe_in_nutshell, excel_reader, info_printer, sys, module_creator,
File "c:\Users\username\OneDrive\Desktop\project\utilities.py", line 18, in <module>
from pycaret.regression import (setup, compare_models, predict_model, plot_model, finalize_model,
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pycaret\regression.py", line 10, in <module>
import pycaret.internal.tabular
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pycaret\internal\tabular.py", line 48, in <module>
import pycaret.internal.preprocess
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pycaret\internal\preprocess.py", line 27, in <module>
from pyod.models.knn import KNN
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pyod\__init__.py", line 4, in <module>
from . import utils
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pyod\utils\__init__.py", line 4, in <module>
from .stat_models import pairwise_distances_no_broadcast
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pyod\utils\stat_models.py", line 11, in <module>
from numba import njit
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\numba\__init__.py", line 42, in <module>
from numba.np.ufunc import (vectorize, guvectorize, threading_layer,
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\numba\np\ufunc\__init__.py", line 3, in <module>
from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\numba\np\ufunc\decorators.py", line 3, in <module>
from numba.np.ufunc import _internal
SystemError: initialization of _internal failed without raising an exception
Logistics
I am running my_project.py in visual studio code on a Windows 10 machine.
All packages are based on Python 3.10 using conda-forge channel
Research
The following pages seem to explain a workaround but I am not sure if I am understanding the issue in here. I would appreciate if you can help me figure this out.
Error on import with numpy HEAD
Update ufunc loop signature resolution to use NumPy
Remove reliance on npy_ ufunc loops.
I had this very same issue today.
Solved it by downgrading Numpy to 1.23.1
So: pip install numpy==1.23.1
Hi so I'm trying to run this code to convert youtube videos into mp3 and download them using pytube and moviepy but I'm running into this:
File "C:/Users/KIIT/AppData/Local/Programs/Python/Python36/ydl2.py", line 2, in <module>
from moviepy.editor import system
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\editor.py", line 33, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 14, in <module>
import proglog
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\proglog\__init__.py", line 5, in <module>
from .proglog import (ProgressLogger, ProgressBarLogger, TqdmProgressBarLogger,
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\proglog\proglog.py", line 4, in <module>
from tqdm import tqdm, tqdm_notebook
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\tqdm\__init__.py", line 1, in <module>
from ._tqdm import tqdm
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\tqdm\_tqdm.py", line 14, in <module>
from ._utils import _supports_unicode, _environ_cols_wrapper, _range, _unich, \
File "C:\Users\KIIT\AppData\Local\Programs\Python\Python36\lib\site-packages\tqdm\_utils.py", line 3, in <module>
from platform import system as _curos
ImportError: cannot import name 'system'
Here's the code:
from pytube import YouTube
from moviepy.editor import system
from moviepy.editor import *
#convert to mp3 and download
youtube_link = 'https://www.youtube.com/watch?v=AaC6v0wCQWg'
y = YouTube(youtube_link)
t = y.streams.filter(only_audio=True).all()
t[0].download(output_path=r"..\Python\ydl2 songs")
Using pytube3 https://github.com/hbmartin/pytube3 you can use y.streams.get_audio_only()
I am using Python 3.7.0
I am not able to use BeautifulSoup attribute of bs4
I have reinstalled the library but is still not working.
from bs4 import BeautifulSoup
import csv
html = open("table.html").read()
soup = BeautifulSoup(html)
table = soup.find("table")
output_rows = []
for table_row in table.findAll('tr'):
columns = table_row.findAll('td')
output_row = []
for column in columns:
output_row.append(column.text)
output_rows.append(output_row)
with open('output.csv', 'wb') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(output_rows)
it is throwing following error:
Traceback (most recent call last):
File "D:\Automation\ReadHtml\html.py", line 1, in <module>
from bs4 import BeautifulSoup
File "D:\Python37\lib\site-packages\bs4\__init__.py", line 34, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "D:\Python37\lib\site-packages\bs4\builder\__init__.py", line 7, in <module>
from bs4.element import (
File "D:\Python37\lib\site-packages\bs4\element.py", line 19, in <module>
from bs4.formatter import (
File "D:\Python37\lib\site-packages\bs4\formatter.py", line 1, in <module>
from bs4.dammit import EntitySubstitution
File "D:\Python37\lib\site-packages\bs4\dammit.py", line 13, in <module>
from html.entities import codepoint2name
File "D:\Automation\ReadHtml\html.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: cannot import name 'BeautifulSoup' from 'bs4' (D:\Python37\lib\site-packages\bs4\__init__.py)
Edit:
I installed using
pip install BeautifulSoup4
also installed
pip install bs4
but it is still not working.
Soved Thanks, just renamed the file from html.py to something.py
# Load the data
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sklearn
oecd = pd.read_csv("oecd.csv", thousands=',')
gd_per_capita = pd.read_csv("gdp_per_capita.csv", thousands=',',delimiter='\t', encoding='latin1', na_values="n/a")
#Prepare the data
country_stats = prepare_country_stats(oecd, gdp_per_capita)
x = np.c_[country_stats["GDP per capita"]]
y = np.c[country_stats["Life satisfaction"]]
#Visualise the data
country_stats.plot(kind='scatter', x="GDP per capita", y='Life satisfaction')
plt.show()
# Select a linear model
model = sklearn.linear_model.LinearRegression()
# Train the code
model.fit(x,y)
# Make a prediction for Cyprus
x_new = [[22587]] # Cyprus GDP per capita
print(model.predict(x_new))
Whenever I try to run this code in Python 3.4.4 this throws up:
Traceback (most recent call last):
File "C:\Users\Ranjan.Ranjan-PC\Desktop\Hands-On\gdp.py", line 6, in <module>
import sklearn
File "C:\Python34\lib\site-packages\sklearn\__init__.py", line 134, in <module>
from .base import clone
File "C:\Python34\lib\site-packages\sklearn\base.py", line 10, in <module>
from scipy import sparse
File "C:\Python34\lib\site-packages\scipy\sparse\__init__.py", line 213, in <module>
from .csr import *
File "C:\Python34\lib\site-packages\scipy\sparse\csr.py", line 13, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: DLL load failed: %1 is not a valid Win32 application.
sklearn has been installed though
What is wrong?
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Python33\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
from matplotlib.figure import Figure, figaspect
File "C:\Python33\lib\site-packages\matplotlib\figure.py", line 36, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "C:\Python33\lib\site-packages\matplotlib\axes.py", line 22, in <module>
import matplotlib.dates as _ # <-registers a date unit converter
File "C:\Python33\lib\site-packages\matplotlib\dates.py", line 119, in <module>
from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
File "C:\Python33\lib\site-packages\dateutil\rrule.py", line 18, in <module>
from six import advance_iterator, integer_types
ImportError: No module named 'six'
>>>
I tried to import matplotlib.pyplot in python 3.3 in windows 7, got above error.
You're missing a dependency, namely 'six'.
You can get it through pip:
pip install six
or from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#six