Showing posts with label Clipboard. Show all posts
Showing posts with label Clipboard. Show all posts

Monday, March 15, 2021

Return values that meet some criteria based in other columns - Pandas

Some simple tasks are much faster and simpler in pandas than in Excel.

For example: return values that meet some criteria based in other columns.


If we want to list all the basins with area greater than 100ha, a simple code will do.

Assuming we had copied this table from excel:


import pandas as pd

df0=pd.read_clipboard()

df0[df0.iloc[:,-1]>100].to_clipboard()


This code will put the result in the clipboard, to paste back into Excel (for ex.).





Thursday, April 25, 2019

Pandas - Reading headers and dates correctly from Clipboard/ CSV

When using pandas funcions read_clipboard() or read_csv() you have to define if your data has headers (column headers) and indexes (row headers).

If you're passing indexes with datetime format, make sure if it will be parsed correctly, indicating it's a datetime and if it has dayfirst format (dd/mm/YYYY).

For example:

pd.read_clipboard(index_col=0, headers=None,parse_dates=True, dayfirst=True)

Is telling pandas that the table in clipboard has no column headers, but have index (row headers) in the first column and it is in datetime format with day first (dd/mm/YYYY).

Thursday, March 30, 2017

Using clipboard in PyQt

You can use the clipboard in your PyQt plugins by using the QApplication.clipboard().
First you import qthe QApplication from PyQt4.QtGui.

from PyQt4.QtGui import QApplication

Then you can create a variable, for example:

self.clip = QApplication.clipboard()

And then set some text to it:

self.clip.setText('some text')


Monday, December 14, 2015

Text string to Excel

Sometimes we just want to handle some data, from or to excel.

Here is a tip that can help in your scripts, when you want to copy data from or to an Excel spreadsheet.

Microsoft Excel recognizes the tabulation character ('\t') as cell separation, and a line break character ('\n') as a normal line break.

For example, if you copy some string data to the clipboard, as explained in previous post, you can paste it to excel cells, if the data is separated by '\t' character.

Monday, November 16, 2015

Using the Windows Clipboard

The Windows Clipboard may be very useful for transferring information for processing in quick python scripts.

To this purpose, we are going to use the "win32clipboard" library, included in python distribution.

First, we have to call the library, as usual:

import win32clipboard

Then, in the code, we have to open the Clipboard:

win32clipboard.OpenClipboard()

Once opened, we can retrieve information that is in the Clipboard, copy information to it, or clear all contentents.

To get information in Clipboard, and store its information in a variable:

clipbVar = win32clipboard.GetClipboardData()

To set it to any value:

win32clipboard.SetClipboardText('testing 123')

To clear the Clipboard:

win32clipboard.EmptyClipboard()

After using the Clipboard, we have to close it, as following:

win32clipboard.CloseClipboard()