python读取excel文件并转为list列表

import pandas as pd
import numpy as np
# read the file
df = pd.read_excel('2021MCMProblemC_DataSet.xlsx')

# select the right data
reports = df.loc[(df['Lab Status'] == 'Positive ID'), ['Detection Date', 'Latitude', 'Longitude']]
ndata = np.array(reports)
reportsList = ndata.tolist()
reportsList = sorted(reportsList, key=lambda s: s[0])  # 排序

引入pandas 和numpy两个包
用pd读excel
df是dataframe格式的文件

接着,我们从df中选取我们需要的数据
我们筛选的列是Lab Status列,选出所有PositiveID的数据的Detection Date’, ‘Latitude’, 'Longitude’信息
python读取excel文件并转为list列表_第1张图片

你可能感兴趣的:(python,python)