Home > Net >  Copy the value of a single cell from a data frame onto clipboard in Python
Copy the value of a single cell from a data frame onto clipboard in Python

Time:05-12

I can't figure out how to copy a specific cell value onto the clipboard so I can paste it.

filtered.to_clipboard(index=False, columns=['ABC']) That gives me a specific column, but I want a specific row and column. For example:

filtered.to_clipboard(index=False, columns=['ABC'], rows=[1])

But that doesn't work. Any help?

CodePudding user response:

You could first select the value, indexing with lists, so that a dataframe is returned. Then you can apply the to_clipboard method:

df = filtered
col = 'ABC'
row = 1

df.loc[[row], [col]].to_clipboard(index=False, header=False)
  • Related