import pandas as pd df = pd.DataFrame({'ID'=[1,2,3],'Name':['Tim','Victor','Nick']}) 创建实例 df.to_excel('D:/Temp/output.xlsx') 创建一个方法 print('Done!')
import pandas as pd
people =pd.read_excel('D:/Temp/People.xlsx') #读People EXcel文件
print(people.shape) #People 文件行列数
print(people.columns) #查询列名
print(people.head(3)) #查询前三行
import pandas as pd people =pd.read_excel('D:/Temp/People.xlsx',header = None) #没有列名 people.columns = ['ID','Type','Title','Firstname','middlename','lastname'] #添加列名 print(people.columns)
import pandas as pd
people =pd.read_excel('D:/Temp/People.xlsx', header = 1) #第一行不是列名,第二行才是
people.set_index('ID',inplace=True) #将ID变为index索引
print(people.columns)
people.to_excel('d:/Temp/output.xlsx') #原文件输出为Output文件
print('Done')
import pandas as pd df = pd.read_excel('D:/Temp/output.xlsx',index_col='ID') #上一步输出的Output虽然没有index 索引 但是不加index_col='ID'在生成Output时还是会多出一个空索引. df.to_excel('D:/Temp/output2.xlsx') print('Done@!')