Unable to read URL - python

My code is the following, it used to run perfectly for quite a while but suddenly got the error message. Tried other stocks data providers like Google & alpha vantage and got the same error message.
import plotly.graph_objects as go
import plotly.express as px
from datetime import datetime
import numpy as np
!pip install ffn
import ffn
import pandas_datareader.data as web
from pandas.plotting import register_matplotlib_converters
from pylab import *
import pandas as pd
import pandas_profiling
import matplotlib.pyplot as plot
from matplotlib import style
%matplotlib inline
stocks = 'alf,mrin,auud,sncr,ddd,ssnt,seac,ttd'
df = ffn.get(stocks, start='06/18/2021').to_returns().dropna()
print(df.as_format('.2%'))
df = df.apply(pd.to_numeric, errors='coerce').fillna(0)
sums = df.select_dtypes(np.number).sum()
sort_sums = sums.sort_values(ascending = False)
pd.set_option('Display.max_rows', len(stocks))
sharpe = ffn.core.calc_sharpe(df)
sharpe = sharpe.sort_values(ascending = False)
df.append({stocks: sharpe},ignore_index=True)
print(str(sort_sums.as_format('.2%')))
print(sharpe.head(10))
df.shape
I'm using Google Colaboratory
Please run the code and you will see the Error message I'm getting (I can't copy it to here).
Please help & thank you very much in advance!

Related

How to import panel in python

I'm trying to import panel in a jupyter notebook in Hvplot but keep getting this error:
ImportError: cannot import name 'url' from 'django.conf.urls' (/Users/***/opt/anaconda3/lib/python3.9/site-packages/django/conf/urls/__init__.py)
Tried using techniques from StackOverflow but nothing works. What do I do?
This is mycode before it breaks:
import pandas as pd
import numpy as np
from django.urls import re_path as url
import panel as pn *** it breaks here
pn.extension('tabulator')
import hvplot.pandas

I got: chart_studio.exceptions.PlotlyRequestError: Authentication credentials were not provided

I am working locally(in my pc) just testing and learning PLOTLY 3.7.5.
with anaconda env active.
The code example is given by plotly
Code:
import plotly.plotly as py # Here all begins (Look)
# import chart_studio.plotly as py # inted of the line bellow (optional to try)
import plotly.graph_objs as go
import pandas as pd
from datetime import datetime
if __name__ == '__main__':
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
trace = go.Ohlc(x=df['Date'],
open=df['AAPL.Open'],
high=df['AAPL.High'],
low=df['AAPL.Low'],
close=df['AAPL.Close'])
data = [trace]
py.iplot(data, filename='simple_ohlc')
note (Look): I got the warning error:
'please install the chart-studio package and use the chart_studio.plotly module instead.'
You need plotly's offline mode to obviate authentication - following https://stackoverflow.com/a/44694854/1021819, rather do:
from plotly.offline import iplot
use below line of code before hitting pilot
cf.go_offline() #will make cufflinks offline
cf.set_config_file(offline=False, world_readable=True)
import pandas as pd
import numpy as np
%matplotlib inline
import plotly.graph_objs as go
from plotly.offline import plot
import chart_studio.plotly as py
import cufflinks as cf
cf.go_offline()
from plotly.offline import download_plotlyjs, init_notebook_mode, plot,iplot
init_notebook_mode(connected='true')
df = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
df.head()
df.iplot(kind='box')
Basics for starting Plotly and Cufflinks section:
import pandas as pd
import numpy as np
%matplotlib inline
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import cufflinks as cf
init_notebook_mode(connected=True)
cf.go_offline()
Call these two below library automatically problem will be solved
import chart_studio.plotly as py

python 'DataFrame' object has no attribute 'to_frame'

I am new to python. Just following some sample code
this is the error I get:
'DataFrame' object has no attribute 'to_frame'
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
import statsmodels
import statsmodels.api as sm
from datetime import datetime
tech_list =['4938.TW','2317.TW']
tickers=['4938.TW','2317.TW']
end= '2014-12-31'
start= '2014-01-01'
print(start)
print (end)
from pandas_datareader import data as pdr
import fix_yahoo_finance as yf
yf.pdr_override(tickers)
data=pdr.get_data_yahoo(tech_list,start,end)
data.to_frame().head(10)
I want to get this
enter image description here
The problem is that your 'data' variable is already a dataframe.
Check with print(type(data))
since it's already a dataframe you can use
print(data.head(10))
to get your result

Bootstraping for DataFrame in python

I am trying to resample my dataset using bootsrtaping technique without success, my code as follow:
import pandas as pd
import numpy as np
from openpyxl import Workbook
from pandas import ExcelWriter
import matplotlib.pyplot as plt
import bootstrap as btstrap
#import scikits.bootstrap as sci
from matplotlib import pyplot as plt
import numpy.random as npr
sta_9147="//Users/talhadidi/Private/Desktop/9147.xlsx"
xlsx=pd.ExcelFile(sta_9147)
df1=pd.read_excel(xlsx,'Sheet1')
df1.columns=df1.columns.astype(str)
x_resample = btstrap(['AveOn','AveOff','AveLd','DOOR_OPEN_SEC'], n=10000)
writer=pd.ExcelWriter("/ Users/talhadidi/Private/Desktop/testt5.xlsx")
df2.to_excel(writer,'Sheet1')
writer.save()
the error i kept getting is :
TypeError: 'module' object is not callable,
could anyone help in, special thanks in advance.

AttributeError: type object 'MinimalFeatureExtractionSettings' has no attribute 'n_processes'

I'm trying to extract features using tsfresh package and extract_features() function.
tsfresh Version: 0.4.0.post0.dev1+ng19fa136
However, I get the following error:
AttributeError: type object 'MinimalFeatureExtractionSettings' has no
attribute 'n_processes'
Code:
import numpy as np
import pandas as pd
column_names = ['time_series1', 'time_series2','time_series3']
ts = np.random.rand(6,3)
df_to_extract = pd.DataFrame(data=ts, columns = column_names)
df_to_extract['id'] = 1
df_to_extract['time'] = np.arange(1,7)
#print(df_to_extract)
import tsfresh
from tsfresh import extract_features
from tsfresh import select_features
from tsfresh.utilities.dataframe_functions import impute
from tsfresh import extract_relevant_features
from tsfresh.feature_extraction import extract_features, MinimalFeatureExtractionSettings
from tsfresh.feature_extraction.settings import *
from tsfresh.feature_extraction.settings import FeatureExtractionSettings
import tsfresh.feature_extraction.settings
from tsfresh import utilities
from tsfresh import feature_extraction
extracted_features = extract_features(df_to_extract,
column_id="id",
column_sort="time",
parallelization= 'per_kind',
feature_extraction_settings= MinimalFeatureExtractionSettings)
Package source code: https://github.com/blue-yonder/tsfresh/blob/master/tsfresh/feature_extraction/extraction.py
I'm using Python 3.5 (Anaconda) on Win10.
I suppose it could be some kind of import error.
How to solve that issue?
Problem solved
To make it work add:
settings= MinimalFeatureExtractionSettings()
extracted_features = extract_features(df_to_extract,
column_id="id",
column_sort="time",
parallelization= 'per_kind',
feature_extraction_settings= settings)
There is no MinimalFeatureExtractionSettings object anymore. It is called MinimalFCParameters now. Thus, you would have to write the following code:
from tsfresh.feature_extraction import extract_features, MinimalFCParameters
...
minimalFCParametersForTsFresh = MinimalFCParameters()
extracted_features = extract_features(df_to_extract,column_id="id",default_fc_parameters = minimalFCParametersForTsFresh)

Categories

Resources