BetterDocs
Home
Docs

Creation | pd.read_clipboard()

It is built on top of pd.read_csv() method.

Method:

pd.read_clipboard(sep='\s+', dtype_backend=<no_default>, **kwargs)

Reads a table of fixed-width formatted lines into DataFrame.

Returns:

pandas.core.frame.DataFrame

Parameters:

sep: str, Optional-

Delimiter for separating data; default is whitespace ('\s+').

import pandas as pd
import pyperclip

# Data to be copied to clipboard
data = """ID\tName\tAge
1\tAlice\t25
2\tBob\t30
3\tCharlie\t35
"""

# Copy the data to the clipboard
pyperclip.copy(data)

# Read the data from the clipboard using pandas
df = pd.read_clipboard(sep='\t')

# Print the DataFrame
print(df)

'''
Output:
   ID     Name  Age
0   1    Alice   25
1   2      Bob   30
2   3  Charlie   35
'''

dtype_backend: None, Optional-

The dtype_backend parameter is new in Pandas 2.0 which is used to specify the backend for handling the types of data when reading a file.

**kwargs Optional-

This parameter allows you to pass additional keyword arguments that are forwarded to the underlying pd.read_csv  method.

import pandas as pd
import pyperclip

# Data to be copied to clipboard
data = """IDabcNameabcAge
1abcAliceabc25
2abcBobabc30
3abcCharlieabc35
"""

# Copy the data to the clipboard
pyperclip.copy(data)

# Read the data from the clipboard using pandas
df = pd.read_clipboard(sep='abc', index_col='ID')

# Print the DataFrame
print(df)

'''
Output:
       Name  Age
ID
1     Alice   25
2       Bob   30
3   Charlie   35
'''

Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy