I am trying to view the imported data through pandas, however when I run the script I am presented with the error "int' object has no attribute 'iloc". I am new here and this is my first post so apologies if I don't know the rules. My code is below.
import pandas as pd
from matplotlib import pyplot
from pandas import read_csv
filename = '/Users/rahulparmeshwar/Documents/Algo Bots/Data/Live Data/Tester.csv'
data = read_csv(filename)
pd.set_option('display.width',100)
pd.DataFrame.head(1)
print(pd)
I am new to Python too.
You want to call head() on your dataframe data, not on the constructor pd.DataFrame.
data = read_csv(filename)
pd.set_option('display.width',100)
print(data.head(1))
Related
I'm getting a TypeError: 'UndefinedType' object is not callable when running the following Altair code.
import altair as alt
from vega_datasets import data
cars = data.cars()
alt.Chart(cars).mark_point().encode(
x=alt.X('Horsepower').axis(tickMinStep=50),
y=alt.Y('Miles_per_Gallon').title('Miles per Gallon'),
color='Origin',
shape='Origin'
)
Make sure you use a recent Vega-Altair version. Method-based syntax for setting channel options is not available in altair<=4.2.2. Install a higher version.
I am trying to create a function in which i want to pass pandas dataframe's column name.
Basically i am using plotly.express and that is what i am embedding into a function.
But when i am doing so, it is saying that plotly requires column name but no colomn name found.
def bar(df,**kwargs):
val=", ".join(f"{key}={value}" for key, value in kwargs.items())
px.bar(df,val).show()
bar(sales,x='Category',y='Quantity')```
How can i solve this.
So that whenever user passes an argument it consider it as a field not just a string.
Any leads will be helpful.
TIA
This is not really a plotly question, but python. Fundamentals of how argument passing works.
Simply you just need to pass the kwargs pass to your function to px.bar()
import plotly.express as px
import pandas as pd
import numpy as np
def bar(df,**kwargs):
px.bar(df,**kwargs).show()
sales = pd.DataFrame({"Category":np.random.choice(list("ABCD"), 20), "Quantity":np.random.randint(1,10,20)})
bar(sales,x='Category',y='Quantity')
I have the following query in Excel using BQL:
=BQL("MEMBERS('INEMCBI LX Equity',type=holdings)";"name";"cols=2;rows=223")
This shows a table of securities of a specific mutual fund. Like this:
enter image description here
I want to get the same information using python in Dataframe structure but I dont know any way to get it.
If you run BQNT<GO> on the terminal, you'll get access to Python BQL examples, but the examples won't work outside of BQNT. Since you mention using =BQL, I'm assuming you have access to a terminal.
Example in BQNT:
import bql
bq = bql.Service()
fund = bq.univ.members("INEMCBI LX Equity", type="HOLDINGS")
name = bq.data.name()
req = bql.Request(fund, {"Fund Holdings": name})
res = bq.execute(req)
data = res[0].df()
data
Run BQNT on your Bloomberg terminal to ensure the BQL environment is installed.
Follow the steps exactly as followed.
Open file explorer
Navigate to C:\blp\bqnt\environments\bqnt-3\Lib\site-packages and copy these folders:
bqapi
bqbreg
bql
bqlmetadata
bqrequest
bqutil
ciso8601
Paste them to your python installation folder %userprofile%\Anaconda3\envs{mypythonenv}\lib\site-packages\
Then you can test this code in your code editor. I use Vscode.
import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt
import bql
bq = bql.Service()
query = """get(px_last)for('AAPL US EQUITY')with(dates=range(-1y,0d),fill='prev')"""
data = bql.combined_df(bq.execute(query)).reset_index()
fig = plt.figure(figsize=(12,8))
sb.lineplot(data=data, x='DATE',y='px_last')
plt.show()
The code below complains that vtk.vtkOBJReader() object has no method SetFileNameMTL().
In the documentation it appears to exist vtkOBJImporter.SetFileNameMTL (Maybe the python wrapper for this is missing?).
How can the material (.mtl) for the object be set when parsing the (.obj) in vtk and made visible in k3d?
import k3d
import vtk
import ipywidgets as widgets
reader = vtk.vtkOBJReader()
reader.SetFileName('sample_obj/Model.obj')
reader.SetFileNameMTL('sample_obj/Model.mtl') #Attribute not found
reader.Update()
plot = k3d.plot()
poly_data = reader.GetOutput()
plot += k3d.vtk_poly_data(poly_data)
plot.display()
You are using vtkOBJReader, not vtkOBJImporter. Those are two different classes. vtkOBJReader is the older class, I think, and only reads in the geometry file. To load the material info, you need to use vtkOBJImporter.
I copied the answer to this stack overflow quesiton Decoding base64 from POST to use in PIL
ie:
from PIL import Image
from io import BytesIO
import base64
data['img'] = '''R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw=='''
im = Image.open(BytesIO(base64.b64decode(data)))
and ran it in my text editor and keeps saying data is undefined but I can't figure out why.
Remove ['img']
from PIL import Image
from io import BytesIO
import base64
data = '''R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw=='''
im = Image.open(BytesIO(base64.b64decode(data)))
Just add data = dict() before the data['img'] = .... data need to be define as a dict before you can access the dict key with the bracket operator.