本项目是基于pandas==1.1.5的版本。以下记录学习pandas库的笔记
def read_excel(
io,
sheet_name=0,
header=0,
names=None,
index_col=None,
usecols=None,
squeeze=False,
dtype=None,
engine=None,
converters=None,
true_values=None,
false_values=None,
skiprows=None,
nrows=None,
na_values=None,
keep_default_na=True,
na_filter=True,
verbose=False,
parse_dates=False,
date_parser=None,
thousands=None,
comment=None,
skipfooter=0,
convert_float=True,
mangle_dupe_cols=True,
)
一、pd.read_excel(file)
利用pandas库处理excel表格。有个excel表格如下:
利用iterrows()处理得到的数值为numpy格式的。更多细节如下所示:
import pandas as pd
for i in pd.read_excel(label_file):
print(i)
print(type(pd.read_excel(label_file)))
for i, row in pd.read_excel(label_file).iterrows():
print(i)
print(row)
print(type(row))
print(row['data'])
print(type(row['data']))
print(row['non'])
print(type(row['non']))
print(row[0])
print(row[1])
print(row[2])
print(row[3])
print(type(row[0]))
print(row.values)
print(type(row.values))
print(row[1:].values)
print(type(row[1:].values))
label = {row['data']: row[1:].values
for _, row in pd.read_excel(label_file).iterrows()}
import numpy as np
label1 = np.array([0,0,1])
print(label1.argmax())
当有个表格如下时:
for i, row in pd.read_excel(label_file).iterrows():
print(i)
print(row)
print(row['data'])
print(type(row['data']))
print(row[1])
print(type(row[1]))
print(row[4])
print(type(row[4]))
print(row.values)
print(type(row.values))
|