Creating Multiple Candlestick charts from a csv file - python

I am trying to create multiple candlestick charts for given date ranges which I have a list of in Excel. I have OHLC daily price data and need to use this data to create roughly 1100 charts.
I would like these charts to be in a printable format after they have been created.
Also, I would like horizontal lines on each chart, as specified prices.
Any help would be much appreciated.

I recommend you check out pypi for the python package index. Some useful packages you should look into are Pandas, MatPlotLib, and xlrd. If you have a specific question about code that you're working on, please come back and ask.

Related

how to make a chart on country map by using python

I want to make a chart on any country's map by using python. For example: To make a record of Covid-19 infected or death toll of a country on that country map, what type of module or how can I do it?
First of all you need a data set as far as I understand. Data you can use for corona virus,
Corona virus data set
Download the csv files here.
Later,
With phyton, you can learn how to transfer to excel.
csv to excel
To make a graphic, to examine here.
pyhton chart
Matplotlib and Seaborn can help you with necessarily this.

How to automatically reduce the range of a chart?

First of all sorry for my bad english as it is not first language.
I have recently started learning python and I am trying to develop a "simple" program, but I have run into a problem.
I am using xlwings to modify and interact with Excel. What I want to achieve (or to know if its possible) is:
I have excel look into data and plot a graph. However this graph sometimes has for example 20 values for the X-Axis and in other cases let's say 10 values for the X-Axis, thus, leaving 10 #NA empty spaces. Based on this, I want to adjust the graph to show only 10 values by changing the range that shapes the graph .
The function get_prod_hours() looks how many values I want on the X-Axis:
def get_prod_hours():
"""From the input gets the production hours to adapt the graphs"""
dt = wb.sheets['Calculatrice']
return dt.range('E24').value
Based on the value gotten from the function I must modify the range of values on the graph (by reducing it).
Solutions as for example create the graphs from scratch are not OK because I would like to only modify the range of the graph because the Excel file is a "standard" on my company.
I hope for something like:
Column A in Excel with values: 1, 2, 3, 4, 5 and get from get_prod_hours() a value of 5, so my graph will have only 5 points and not for example 6 of which one is #NA.
Thank you very much, and sorry for the wall of text.
The xlwings API doesn't offer a lot of options for charts (see https://docs.xlwings.org/en/stable/api.html?highlight=charts#xlwings.main.Charts).
Try to find the chart in wb.sheets[0].charts.
The range can then be modified with
range = xw.Range((1,1), (get_prod_hours(),1))
set_source_data(wb.sheets[0].range(range))
But from looking at the API and knowing how many options Excel charts have, the API feels too thin.
If this doesn't work, an option is to add a VBA macro which modifies the chart and call that. See How do I call an Excel macro from Python using xlwings?

Can I translate/duplicate an existing graph in Excel into Python?

I have many graphs in Excel that I would like to convert to Python but am struggling with how to do so using Matplotlib. Is there a package or method that would essentially convert/translate all the formatting and data series selection into python?
Once I could see a few examples of the correct code I think I could start doing this directly in python but I do not have much experience manually creating graph code (I use Excel insert graphs mostly) so am looking for a bridge.

Plotting a Apache DataFrame

is there any possibility to plot an APACHE Dataframe? I figured it out while converting it to a Pandas dataframe which takes a lot of time and is not my goal.
In particular, the goal is to plot a map out of an Apache DataFrame without convertion to a Pandas DataFrame.
With plotting I mean to use a library such as matplotlib or plotly for plotting a graph or something similar.
Any ideas?
Thanks!
Do you mean plot an Spark Dataframe?
In that case, you could do something like this, having yourDF as your Dataframe:
yourDF.show(100, truncate=false)
This will show in your logging your dataframe structure and values (in this case, first 100 rows) the same way you'll find in pandas. With the truncate option you specify you want to show the whole dataframe instead of a reduced version.
EDIT: in order to directly plot from a dataframe, please check the plotly lib, o the
display(dataframe)
function, documented here.

Create bokeh timeseries graph using database info

Note from maintainers: this question is about the obsolete bokeh.charts API removed several years ago. For an example of timeseries charts in modern Bokeh, see here:
https://docs.bokeh.org/en/latest/docs/gallery/range_tool.html
I'm trying to create a timeseries graph with bokeh. This is my first time using bokeh, and my first time dealing with pandas as well. Our customers receive reviews on their products. I'm trying to create a graph which shows how their average review rating has changed over time.
Our database contains the dates of each review. We also have the average review value for that date. I need to plot a line with the x axis being dates and the y axis being the review value range (1 through 10).
When I accepted this project I thought it would be easy. How wrong I was. I found a timeseries example that looks good. Unfortunately, the example completely glosses over what is the most difficult part about creating a solution. Specifically, it does not show how to create an appropriate data structure from your source data. The example is retrieving pre-built datastructures from the yahoo api. I've tried examining these structures, but they don't exactly look straightforward to me.
I found a page explaining pandas structs. It is a little difficult for me to understand. Particularly confusing to me is how to represent points in the graph without necessarily labeling those points. For example the y axis should display whole numbers, but data points need not intersect with the whole number value. The page I found is linked below:
http://pandas.pydata.org/pandas-docs/stable/dsintro.html
Does anyone know of a working example for the timeseries chart type which exemplifies how to build the necessary data structure?
UPDATE:
Thanks to the answer below I toyed around with just passing lists into lines. It didn't occur to me that I could do this, but it works very well. For example:
date = [1/11/2011, 1/12/2011. 1/13/2011, 4/5/2014]
rating = [4, 4, 5, 2]
line(
date, # x coordinates
rating, # y coordinates
color='#A6CEE3', # set a color for the line
x_axis_type = "datetime", # NOTE: only needed on first
tools="pan,wheel_zoom,box_zoom,reset,previewsave" # NOTE: only needed on first
)
You don't have to use Pandas, you simply need to supply a sequence of x-values and a sequence of y-values. These can be plain Python lists of numbers, or NumPy arrays, or Pandas Series. Here is another time series example that uses just NumPy arrays:
http://docs.bokeh.org/en/latest/docs/gallery/color_scatter.html
EDIT: link updated

Categories

Resources