For whatever reason, clipboard functionalities from Rython are under-utilized. One utility function for reversing backslashes is found here. This post demonstrates how you can use the clipboard to circumvent saving and loading files. It’s convenient for when you just want the quick insight or visual, rather than a full-blown replicable process.
Consider the following scenario: you come across a webpage containing a table, and would like to compute some basic statistics, or visualize a couple of columns from that table. A usual workflow for such a minuscule task is to (1) copy the table, (2) pasting it into Excel, (3) saving the Excel sheet, and (4) reading it into Rython.
Can we not just copy the table and read it directly from the clipboard? Yes we can!
Like so (click to play, and the Rython code below):
The code is below:
tmpdat <- read.csv("clipboard", sep= "", row.names= NULL, fill= T, header= F) dim(tmpdat) ; head(tmpdat) plot(tmpdat[,13]~ seq(NROW(tmpdat)) , ty= "b", col= "darkgreen", xlab="Time", ylab="CHF (millions)", pch=19, las=1) grid()
import pandas as pd import matplotlib.pyplot as plt tmpdat = pd.read_clipboard(sep= " ") print(tmpdat.shape) ; print(tmpdat.head()) fig= plt.figure(figsize=(10, 6)) fig.subplots_adjust(left=0.15) plt.plot(tmpdat.iloc[:, 12], marker='o', color='darkgreen') plt.xlabel('Time') plt.ylabel('CHF (millions)') plt.grid(True) plt.show()