拆分单元格内容
import pandas as pd
employees = pd.read_excel('C:/employee.xlsx')
df = employees['Full Name'].str.split(n=2, expand=True)
employees['First Name'] = df[0]
employees['Last Name'] = df[1]
数据统计,统计每个学员的总分,平均分,所有学员各科平均分,总分
students = pd.read_excel('C:/students.xlsx')
temp = students[['Test1', 'Test2', 'Test3']]
row_sum = temp.sum(axis=1)
row_mean = temp.mean(axis=1)
students['Total'] = row_sum
students['Average'] = row_mean
col_mean = students[['Test1', 'Test2', 'Test3', 'Total', 'Average']].mean(axis=0)
col_mean['Name'] = 'Summary'
students.append(col_mean, ignore_index=True)
去除重复数据
students.drop_duplicates(subset='Name')
找出重复数据
# 根据Name 查找是否有重复行,重复的话dupe值为True,否则为False
dupe = students.duplicated(subset='Name')
# 获取重复的行
dupe = dupe[dupe==True]
# 找到重复数据
dupe_data = students.iloc[dupe.index]
旋转表格,行转列,列转行
table = video.transpose()
读取CSV,TXT数据
table = pd.read_csv('C:/data.csv', sep='\t', index_col='ID')
来源:oschina
链接:https://my.oschina.net/ski/blog/3182998