摘要:#数据合并一对一 #相同的列进行合并 import pandas as pd df1=pd.read_excel('student1.xlsx') df2=pd.read_excel('student2.xlsx') #dfl #测试数据读取 #数据合并 new_df=pd.merge(df1,df
阅读全文
随笔分类 - 数据分析全家桶
摘要:#数据位移 #数据位移 import pandas as pd data=[7532, 3937, 9447, 8765, 4564] index=[1, 2, 3, 4, 5] df=pd. DataFrame (data=data, index=index, columns=['OPPO' ])
阅读全文
摘要:#通过字典进行分组统计 #通过字典进行分组统计 import pandas as pd pd.set_option ( 'display.unicode.east_asian_width', True) pd.set_option ('display.max_columns',500) pd.set
阅读全文
摘要:#自定义函数实现分组统计 #能过自定义的函数实现分组统计 import pandas as pd df=pd.read_excel('电脑配件销售记录.xlsx') #print (df. head ())) #回顾知识点 # print (type (df['产品名称'])) #Series pr
阅读全文
摘要:##分组对列采用聚合函数 #分组对列采用聚合函数 import pandas as pd pd.set_option ('display.unicode.east_asian_width',True) df=pd.read_excel('电脑配件销售记录.xlsx') #print(df.head(
阅读全文
摘要:##分组数据选代 (遍历分组) for name, group in df1.groupby('产品名称'): #分组数据选代 #分组并按指定列进行计算 import pandas as pd pd.set_option ('display.unicode.east_asian_width',Tru
阅读全文
摘要:##按照一列分组统计 #按照一列分组统计 import pandas as pd pd.set_option ('display.unicode.east_asian_width',True) df=pd.read_excel('电脑配件销售记录.xlsx') print (df) print ('
阅读全文
摘要:#apply(), map(), applymap()区别 apply()可用于Series和DataFrame,DataFrame只能运用到一行或一列,如合计的新增列 map()只适用于Series applymap()将函数应用到DataFrame中的每一个元素中 # apply(), map(
阅读全文
摘要:##设置千位分隔符 apply() #设置千位分隔符 apply() import pandas as pd pd.set_option ('display.unicode.east_asian_width',True) df=pd.read_excel ('msb课程记录.xls') print
阅读全文
摘要:# apply()设置百分比 map ()设置百分比 #设置百分比 import pandas as pd df=pd.read_excel ('格式化数据.xls') print (df) print('1. apply()设置百分比 ') df['百分比']=df ['A1']. apply (
阅读全文
摘要:#设置小数位数 import pandas as pd pd.set_option ('display.unicode.east_asian_width', True) df=pd.read_excel('格式化数据.xls') print (df) print (df.round(2)) #对df
阅读全文
摘要:#求标准差 #求标准差 import pandas as pd pd.set_option ('display.unicode.east_asian_width', True) data=[[100,90,100],[100,76,76],[76,90,76]] columns=['数学','语文'
阅读全文
摘要:#求众数 import pandas as pd pd.set_option ('display.unicode.east_asian_width', True) data=[[100,90,100],[100,76,76],[76,90,76]] columns=['数学','语文','英语']
阅读全文
摘要:#最大最小值-中位数 import pandas as pd pd.set_option ('display.unicode.east_asian_width', True) data=[[100,90,80],[98,67,56],[56,56,45]] columns=['数学','语文','英
阅读全文
摘要:#求和 和 计算平均值 import pandas as pd pd.set_option ('display.unicode.east_asian_width', True) data=[[100,90,80],[98,67,56],[56,56,45]] columns=['数学','语文','
阅读全文
摘要:#按某列数据大小排名 import pandas as pd pd.set_option('display.unicode.east_asian_width',True) # 规整格式 df=pd.read_excel('电脑配件销售记录.xlsx') df['顺序排名']=df['数量'].ran
阅读全文
摘要:#按某列降序排序 import pandas as pd pd.set_option('display.unicode.east_asian_width',True) # 规整格式 df=pd.read_excel('电脑配件销售记录.xlsx') print(df.head()) #head()
阅读全文
摘要:#设置某列为行索引 import pandas as pd df=pd.read_excel('msb课程记录.xls') #print(df) df=df.set_index (['买家会员名']) print(df) 买家实际支付金额 课程总数量 课程标题 类别 \ 买家会员名 msb001 3
阅读全文
摘要:#重新设置索引,多出的索引数据填充 #重新设置索引,多出的索引数据填充 import pandas as pd s=pd.Series([11, 22, 33], index=[1,2,3]) print(s) #重新设置索引 print(s.reindex(range(1, 6))) #多出来两为
阅读全文
浙公网安备 33010602011771号