可以使用 pandas read_clipboard读取系列更简单的方法吗? [英] Could there be an easier way to use pandas read_clipboard to read a Series?

查看:68
本文介绍了可以使用 pandas read_clipboard读取系列更简单的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我想使用 read_clipboard 来阅读 Series es,而我不得不这样做:

Some times, i want use read_clipboard to read Serieses, and i would have to do:

pd.Series(pd.read_clipboard(header=None).values[:,0])

如果有更简单的方法,那会很好吗?

So would it be nice if there was an easier way?

对于数据帧,我可以很轻松地做到这一点,例如:

I can do it very easily for data-frames, like:

pd.read_clipboard()

就是这样.

但是对于 Series ,它的衬里更长.

But for Series, it's much longer-one-liner.

那么有没有更简单的方法?

So is there an easier way?

我不知道吗?

有任何秘密密码吗?

推荐答案

将此复制到剪贴板:

1
2
3

更好的方法是使用 squeeze = True 作为参数.

Better would be to use squeeze=True as an argument.

pd.read_clipboard(header=None, squeeze=True)

0    1
1    2
2    3
Name: 0, dtype: int64

哪个返回系列.如果要命名系列,请使用 names 参数:

Which returns a Series. If you want to name the series, use the names parameter:

pd.read_clipboard(header=None, squeeze=True, names=['mycol'])

0    1
1    2
2    3
Name: mycol, dtype: int64

实际上, read_clipboard 使用pyperclip从剪贴板读取内容,并将文本发送到

Actually, read_clipboard uses pyperclip to read from the clipboard, and sends the text to read_table.

阅读受支持的参数.

这篇关于可以使用 pandas read_clipboard读取系列更简单的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆