import pandas as pd
people=pd.read_excel('*.xlsx')#读入excel
people.columns=['ID','','','','']#设置列名
people.set_index('ID',inplace=True)#设置ID作为参考指标数
people.to_excel('*.xlsx')
Series使用——输出table
import pandas as pd
s1=pd.Series([1,2,3],index=[1,2,3],name='A')
s2=pd.Series([10,20,30],index=[1,2,3],name='B')
s3=pd.Series([100,200,300],index=[1,2,3],name='C')
df=pd.DataFrame({s1.name:s1,s2.name:s2,s3.name:s3})#index有对齐关系print(df)
单元格数据运算
#方法一
books['Price']=books['ListPrice']*books['Discount']#重载,单元格对应相乘#方法二for i in books.index:
books['Price'].at[i]=books['ListPrice'].at[i]*books['Discount'].at[i]#apply() 用于间接调用函数
books['ListPrice']=books['ListPrice'].apply(add_2)
#方法一
students.plot.bar(x='Field',y='Number',color='orange',title='international students by field')#方法二
plt.bar(students.Field,students.Number)
plt.xticks(students.Field,rotation=90)
plt.xlabel('Field')
plt.ylabel('Number')
plt.title('International Students By Field',fontsize=16)
plt.tight_layout()
plt.show()