Skip to content

Knighthood2001/numpytable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

numpytable

每次复制Excel表格的数据到Python中,都要手动添加括号和逗号,非常繁琐。

目的:快速将Excel等工具复制的表格文本转换为NumPy数组,告别手动添加括号和逗号的繁琐操作。

安装

pip install numpytable

用法

  1. 在Excel(或其他表格工具)中选中数据并复制(元素间默认用制表符分隔):

    2.2681	6.623	2.6459
    2.3407	6.574	2.1304
    2.8451	6.4258	2.1178
    
  2. 在Python中用from_table函数转换:

    import numpy as np
    from numpytable import from_table
    
    # 直接粘贴复制的文本,用三引号包裹
    data = np.array(from_table("""
    2.2681	6.623	2.6459
    2.3407	6.574	2.1304
    2.8451	6.4258	2.1178
    """))
    
    print(data)
    # 输出:
    # [[2.2681 6.623  2.6459]
    #  [2.3407 6.574  2.1304]
    #  [2.8451 6.4258 2.1178]]

特性

  • 自动处理换行和制表符,无需手动格式化
  • 支持整数、浮点数自动识别
  • 检测并警告行数不一致的情况
  • 轻量依赖(仅需numpy)

About

快速将Excel等工具复制的表格文本转换为NumPy数组,告别手动添加括号和逗号的繁琐操作。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages