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
Related
import profile
import pandas as pd
from pandas_profiling import profile_report as report
data = pd.read_csv(r"ifsc-code-of-syndicate-bank-_All-India_.csv")
print(data)
#generate a report
profile = report(data)
profile.to_file(output_file="ifsc.html")
As per the official documentation of this package, you should try this import instead:
from pandas_profiling import ProfileReport as report
https://pandas-profiling.ydata.ai/docs/master/pages/getting_started/quickstart.html
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!
I am using Google Co lab
ValueError: unsupported pickle protocol: 5
python version 3.7.10
Link: https://drive.google.com/folderview?id=1eF1BlfewbRhtgdJySjzU6esefYnr2xAC
import pandas as pd
import datetime
import numpy as np
import matplotlib.pyplot as
plt
from glob import glob
from dateutil.relativedelta.
import relativedelta, TH
import pickle
path =
pd.DataFrame
(glob('/content/drive/MyDrive
/sample_nfo_201920_data/
complete_nfo_data_2019-01-
01.pkl'),columns =
['location'])
path['location']
.iloc[0].split('_')[-1]
.split('.')[0]
path['data_date']=
path['location'].apply(lambda.
x: x.split('_')[-1].split('.')
[0])
path['data_date']=
path['data_date'].
apply(lambda. x:
datetime.datetime.
strptime(x,'%Y-%m-%d'))
path=path.sort_values
(['data_date'])
pd.read_pickle
("/content/drive/MyDrive
/sample_nfo_2019-
20_data/complete_nfo_data_
2019-01-01.pkl")
Error:
ValueError: unsupported pickle protocol:5
Use pckle5 or you can do this all in Python 3.8+.
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.
I tried running the following program
import numpy as np
data = np.genfromtxt('data.csv', delimiter = ',')
which gives
AttributeError: 'module' object has no attribute 'genfromtxt'
Help much appreciated
You must import matplotlib and it will work
copy and past next code
import numpy as np
from matplotlib import pyplot as plt
data = np.genfromtxt('data.csv', delimiter = ',')