I am creating some documentation using Sphinx and I want to use the bokeh.sphinxext to include Bokeh plots with the documentation. This seems like an easy thing to do given this example. However, the data that I want to use to generate the plot is stored within a CSV file. I've tried putting my CSV file into the same directory, and using .. include:: data.csv in the same RST document, but that didn't work.
How can I reference an external file when creating Bokeh plots using Sphinx?
.. include:: data.csv
.. bokeh-plot::
import pandas as pd
from bokeh.plotting import figure, output_file, show
output_file("example.html")
df = pd.read_csv('data.csv')
p = figure(title="example", plot_width=300, plot_height=300)
p.line(df['x'], df['y'], line_width=2)
show(p)
Just because of how the extension operates, the current working directory when the code executes (i.e. what is returned by the os.getcwd() function) is the top level of your Sphinx project. You will need to construct a path to your data file based on that. E.g. if your file is under the source/docs directory of your Sphinx project, it might be:
df = pd.read_csv(os.join('source', 'docs', 'data.csv')
Related
I need to import a file folder with thousands of files. They are not csv, xlsx, txt files, they just say file under type(data type). I have tried multiple ways to import them as well as running R as an administrator.
I have tried different permutations of this code using different read.csv,delim etc but I am unable to import the files.
baseball <- read.csv('C:/Users/nfisc/Desktop/Spring 2021/CIS 576/Homework/Homework 5/rec.sport.baseball', stringsAsFactors = F)
Any help would be appreciated.
Can you be more specific about what these files are? Does it open into Excel? What kind of data does it represent?
Without an extension, it may be difficult to import.
If you right-click the files and go to "properties", what does it say under "Type of File"?
I know that this is late, but I figured out how to input text data. The original issue also was that the file was a rar file and not a zip file.
Import text data # Make V Corpus from a specified directory
baseball_messages <- tm::VCorpus(tm::DirSource("C:/Users/nfisc/Desktop/Spring 2021/CIS 576/Homework/Homework 5/usebaseball"))
hockey_messages <- tm::VCorpus(tm::DirSource("C:/Users/nfisc/Desktop/Spring 2021/CIS 576/Homework/Homework 5/usehockey"))
In org-mode, I can name the output of a code block and include it elsewhere in the document.
Is it possible to do this (or something similar) in a colab .ipynb file, or within a Jupyter notebook in general?
For example, I can make a cell with some Python code that generates a plot:
import matplotlib.pyplot as plt
plt.plot([0,2,1,4,9])
After executing, the plot appears below the code cell. So far so good.
But how do I capture this plot and to use it elsewhere in the notebook?
My hope is there is some syntax so that I can include the plot in a markdown cell, for example:
# this is my title
As you can see, the numbers go up and down in the plot:
![][some_magic_link_here]
Here is some more text to explain the plot.
Does such a feature exist in colab?
Good news - embedding an image in another markdown cell is self-service. Here's an example:
Full notebook:
https://colab.research.google.com/drive/1PF-hT-m8eZN2CBzFkMp9Bvzj9pSBQVYn
The key bits are:
Using IPython.display.Markdown is order to programmatically construct the markdown.
In addition to rendering, save the matplotlib figure using savefig.
Include the image data in the markdown after base64 encoding.
Every time I type in the file name in this case "labelled edited.xlsx" (perfectly - it was copied from the import box when using the import function from the menu into an R notebook), then try to run it, it says 'Error: path does not exist'. However using the import menu works. If I copy and paste the exact same thing from the import box:
labellededited <- read_excel("labelled edited.xlsx", col_names = TRUE, .name_repair="minimal")
into the notebook and run it immediately, it works perfectly. However, when I close R, open it again, set the working directory (without changing a single thing in the directory folder so the file names are the same), it returns the error even though absolutely nothing has changed - I just restarted R.
In addition to this, copying the code from the notebook into the import box on the bottom right will import the dataset perfectly, as does copying the line of code into the console. It only happens when I press cmd+enter directly from the notebook.
Any tips on fixing this? I know it's not a big deal, but ideally, i'd like to create a code, set the directory and then just let it run.
The problem has to do with RStudio and file types. In order to use the keyboard shortcuts (Ctrl+Enter) the commands have to be saved as an R script file. So start a new one (Ctrl+Shift+N) and copy the commands from the .Rmd file, and try again.
Hi you can use this i guess,
set working directory using setwd("your Path/") then
library(readxl)
if you want to import xlsx use read_xlsx , if you want to import xls use read_xls
labellededited <- read_xlsx("labelled edited.xlsx",sheet = "select sheet number"(default it will consider as first sheet)
more better way you can keep path inside the code and import the file(if you don't move the file it will import without any error)
labellededited <- read_xlsx("yourpath/labelled edited.xlsx",sheet = "select sheet number")
Hope it helps
library("readxl")
my_data <- read_excel("GVA.xlsx")
my_data
however the console says the path does not exist.
How can I import excel/csv files and know that the file will always be found.
Why does this not work?
p.s.
I am new to R
Well, is 'GVA.xlsx' in your working directory? If not, R can't find it because you're not mapping to anything outside of your current directory. You can navigate to the file by clicking on: File > Import Dataset > From Excel. Browse to your file and set any required import options. R will actually create the code to map to the file in question.
To use a dataset in Bokeh, it is common to import pandas as well and use a Pandas DataFrame as data. It is also possible to create ColumnDataSource from Pandas DataFrame.
But is it possible to go straight from a csv file (or any other tabular source data) to Bokeh without creating using Pandas as a bridge, and how?
Bokeh ColumnDataSource are built directly from python dictionaries. Simply use:
ColumnDataSouce(data=dict(...))
Without knowing your specific data format, I'd refer to you to use many of the other answers on SO on reading a csv file and creating a Python dictionary. You can also take a look at the official docs on DictReader.