我有一个 Excel 文件,我想读取该 Excel 文件中的特定列,我使用以下代码执行此操作:
import pandas as pd
import xlrd
file_location = input('Where is the file located? Please input the file path here. ')
column = input('In what column is the code? ')
code_array = pd.read_excel(file_location, usecols=column)
for i in code_array:
print(code_array)
并且该代码在控制台中打印出该列的内容。现在,该列的文本如下:12345 - Description。我只想提取号码,我该怎么做?我想过使用 [0:5] 中的子字符串或将数据转换为字符串数组,但我不确定该怎么做。
慕村225694
慕码人8056858
随时随地看视频慕课网APP
相关分类