この記事が該当すると思われます。
回答を見ると、csvファイルを(Google Colab/Driveにアップロードして) Colabの中でクリップボード経由ではなく直接書き込んでからダウンロードしているように見えます。
試してみてください。
ちなみに今作業しているのがGoogle Colabというだけで実際に動作させるのは別環境というのなら、その実環境で動作確認すれば今のままでも動くかもしれませんね。
日本語の関連しそうな記事はこちら
【google Colab】 簡単なcsvファイル操作まとめ【python】
英語の該当記事
How can I copy a dataframe to my clipboard (or workaround) from Google Colaboratory?
質問
I'm building a web scraper for a non-technical user on google colaboratory and want the output of that scraper which is in the form of a pandas dataframe to be "copy pastable" with a single inline command.
The execution of df.to_clipboard() results in the following error:
google colaboratoryの技術者以外のユーザー向けにWebスクレイパーを構築しています。パンダのデータフレーム形式のスクレイパーの出力を、1つのインラインコマンドで「コピーペースト可能」にする必要があります。
df.to_clipboard()を実行すると、次のエラーが発生します。
エラーの詳細は省略
PyperclipException:
Pyperclip could not find a copy/paste mechanism for your system.
For more information, please visit https://pyperclip.readthedocs.org
回答
Got the answer!
Not intuitive but located in Google's Colab documentation:
答えを得た!
直感的ではありませんが、GoogleのColabドキュメントにあります。
from google.colab import files
with open('example.csv', 'w') as f:
f.write(df.to_csv())
files.download('example.csv')
類似の記事(Googleではない別サービス)
pandas.read_clipboard from cloud-hosted jupyter?
質問
I am running a Data8 instance of JupyterHub running JupyterLab on a server, and pd.read_clipboard() does not seem to work. I see the same problem in google colab.
サーバーでJupyterLabを実行しているJupyterHubのData8インスタンスを実行していますが、pd.read_clipboard()が機能しないようです。 Google colabでも同じ問題が発生します。
import pandas as pd
pd.read_clipboard()
回答(こちらは承認無しです)
No. The machine is run in the cloud. Python from there cannot access your local machine to get clipboard content.
I tried Javascript clipboad api, but it didn't work probably because the output is in an iframe which isn't allow access to clipboard either. If it did, this would have worked.
いいえ。マシンはクラウドで実行されます。 そこからPythonは、ローカルコンピューターにアクセスしてクリップボードのコンテンツを取得できません。
Javascript clipboad apiを試しましたが、おそらく出力がiframeにあり、クリップボードにもアクセスできないため、機能しませんでした。 もしそうなら、これはうまくいっただろう。
from google.colab.output import eval_js
text = eval_js("navigator.clipboard.readText()")