import pandas as pd import numpy as np import matplotlib.pyplot as plt # 设置输出结果列对齐 pd.set_option('display.unicode.ambiguous_as_wide',True) pd.set_option('display.unicode.east_asian_width',True)
In [100]:
mydict = [{'a': 1, 'b': 2, 'c': 3, 'd': 4}, {'a': 100, 'b': 200, 'c': 300, 'd': 400}, {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 }, {'a': 10000, 'b': 20000, 'c': 30000, 'd': 40000 }, {'a': 100000, 'b': 200000, 'c': 300000, 'd': 400000 }] df = pd.DataFrame(mydict) # 插入一个列-学号 # student_ID = pd.Series([101,102,103,104,105],name = 'ID') # df.insert(0,column='ID',value = student_ID) # df.set_index(['ID'],inplace = True) # print(df.columns) df
Out[100]:
In [101]:
print(type(df.iloc[0])) df.iloc[0]
Out[101]:
In [102]:
print(type(df.iloc[[0]])) df.iloc[[0]]
Out[102]:
In [103]:
print(type(df.iloc[1])) df.iloc[1]
Out[103]:
In [104]:
print(type(df.iloc[[1]])) df.iloc[[1]]
Out[104]:
In [105]:
print(type(df.iloc[[1,2,3]])) df.iloc[[1,2,3]]
Out[105]:
In [106]:
print(type(df.iloc[1:3])) df.iloc[1:4]
Out[106]:
In [ ]: