Stylerframe to html in a Plotly Graph - python

I have recently started learning Python. To automate a report, I'm reading excel data and plotting some graphs using Plotly. But I also want to display a subset of the table data as-is i.e. retaining all the formatting (esp. the formatted colors of the underlying sheet)
I'm able to read the table with the same formating as the table using StylerFrame
sf = StyleFrame.read_excel(s_filename, engine='openpyxl',read_style=True)
but don't know how to add this to the html.
I have tried the workaround where I read the table as a dataframe, style it and render() it to an html. This works.
But I would prefer to show the StylerFrame object on an Html instead. Please help.

Related

Display Pandas Dataframe PowerBI

PowerBi does not allow display of pandas dataframe in page. Requires a plot.
I am working with the python scripting function in PowerBi. I would like to display a pandas dataframe in the page but when I try to print(dataset) I get the following error (https://i.stack.imgur.com/4BWvT.png)
Is there a neat way to display a pandas table in the page? Also, if there is a lot or rows in the data, I would like to be able to scroll through it in the page.
The Python visual turns data into an image. You can sue the Python step in Power Query if you want to output the Dataframe for use in your report.

Python Financial Chart Scraping

Right now I'm trying to scrape the dividend yield from a chart using the following code.
df = pd.read_html('https://www.macrotrends.net/stocks/charts/BMO/Bank-of-Montreal/dividend-yield-history')
df = df[0].dropna()
But the code wont pick up the chart's data.
Any suggestions on pulling it from the website?
Here is the specific link I'm trying to use: https://www.macrotrends.net/stocks/charts/BMO/Bank-of-Montreal/dividend-yield-history
I've used the code for picking up the book values but the objects they're using for the dividends and book values must be different.
Maybe I could use Beautiful Soup?
Sadly that website is rendered dynamically, so there's nothing in the html pandas is getting to scrape from. (The chart is loaded after the page). Scraping manually isn't going to help you here, because the data isn't there. (It's fetched after the page is loaded.)
You can either find an api which provides the data (best, quite possible given the content), work out where the page is fetching its data from and see if you can get it directly (better if possible), or use something like selenium to control a real browser, render the page, get the html, and then use that.

How to load and plot csv file using altair package in python?

I have a csv file which has 200000 lines and I would like to plot the data files using altair packagae. Documentation states that for large files, data needs to be passed as URL. This is what I have till now.
import altair
alt.data_transformers.enable('csv')
url = 'path/to/data'
chart = alt.chart(url).mark_line.encode(x= 'time:T', y = 'current:Q')
chart.save('name.html')
But this does not seem to work. Am I missing something obvious here?
When you pass a dataset by URL and save the chart to HTML, the important thing is that the URL is valid for the web browser you use to view the HTML file.
So if you are viewing the chart locally and want to load a local file, use an appropriate file:// URL. If you plan to view the file within a web server that supports relative URLs for loading resources, pass the relative URL between the location of the HTML file and the location of the data file.
But, as a side-note, you mention your data has 200,000 rows: no matter how you pass the data to the Vega-Lite renderer, it's unlikely to perform well with that much data. My personal rule-of-thumb is to avoid Altair/Vega-Lite for datasets with more than ~10,000 rows or so.
Apart from what #jakevdp said, one more thing that I noticed was that in defining your plot, you missed out on the brackets "()" after mark_line in your code.
I tried implementing the code on a smaller dataset with this modification, and it worked great.

how to print a table for a pandas data frame in Pyscripter?

Is there a way to show a pandas data frame in Pyscripter in a table form? Sure a data frame shows up on the python interface, but i could not find an option to print it in a more graphical , eye-friendly table form... Any help would be much appreciated
Assuming you are using SQL to wrangle your data for you tabular analysis.
Visit https://mode.com/example-gallery/python_dataframe_styling/
It's a great place to learn dataframe styling.

How to draw an html table using bokeh?

I am new to bokeh, I search for examples in the documentation but it appears to me there is not in built method for creating tables. I have some data that I want to show in tabular format. I was wondering what is the easiest way to do that using Bokeh?
The reason I want to draw tables using Bokeh is because I am trying to put a table and two bar charts in the same html report. I was hoping to use one library(Bokeh) to do all my drawing because otherwise I will have to generate table using html generator and then add the html for bar chart generated via Bokeh to that. Hope that explains.
There's no built-in support to create an HTML table as of Bokeh 0.9.1, however it is very simple to embed Bokeh plots and widgets inside your own custom HTML templates. For instance, the new spectrogram shows a very customized HTML document with Bokeh plots and widgets embedded:
https://www.youtube.com/watch?v=L6p7Cd3uDis
So, I would recommend taking this approach. The documentation for embedding is located here:
http://docs.bokeh.org/en/latest/docs/user_guide/embed.html

Categories