bar

ValueError: Grouper for <something> not 1-dimensional

匿名 (未验证) 提交于 2019-12-03 00:48:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm have the following code which creates a table and a barplot via seaborn. #Building a dataframe grouped by the # of Engagement Types sales_type = sales.groupby('# of Engagement Types').sum() #Calculating the % of people who bought the course by # engagement types sales_type['% Sales per Participants'] = round(100*(sales_type['Sales'] / sales_type['Had an Engagement']), 2) #Calculating the # of people who didn't have any engagements sales_type.set_value(index=0, col='Had an Engagement', value=sales[sales['Had an Engagement']==0].count()[

C++ error - “member initializer expression list treated as compound expression”

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm getting a C++ compiler error which I'm not familiar with. Probably a really stupid mistake, but I can't quite put my finger on it. Error: test.cpp:27: error: member initializer expression list treated as compound expression test.cpp:27: warning: left-hand operand of comma has no effect test.cpp:27: error: invalid initialization of reference of type ‘const Bar&’ from expression of type ‘int’ Code: 1 #include <iostream> 2 3 class Foo { 4 public: 5 Foo(float f) : 6 m_f(f) 7 {} 8 9 float m_f; 10 }; 11 12 class Bar { 13 public: 14 Bar(const

Grouped bar chart on R using ggplot2

匿名 (未验证) 提交于 2019-12-03 00:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I create a grouped bar chart on R using ggplot2 using this data? Person Cats Dogs Mr. A 3 1 Mr. B 4 2 So that it shows that shows number of pets owned per person, with this layout Bar chart of pets I have a text file with this data and have used read.delim to read the file on R. I have used this code but it does not produce the bar plot I am looking for. ggplot(data=pets, aes(x=Person, y=Cats, fill=Dogs)) + geom_bar(stat="identity", position=position_dodge()) I am new to R, any help would be appreciated. Thanks in advance. 回答1: To

数据规整

匿名 (未验证) 提交于 2019-12-03 00:39:02
1.丢弃指定轴上的数据 data=pd.DataFrame(np.arange(16).reshape(4,4),index=[ ‘ Shenzhen ‘ , ‘ Guangzhou ‘ , ‘ Beijing ‘ , ‘ Shanghai ‘ ],columns=[ ‘ one ‘ , ‘ two ‘ , ‘ three ‘ , ‘ four ‘ ]) data one two three four Shenzhen 0 1 2 3 Guangzhou 4 5 6 7 Beijing 8 9 10 11 Shanghai 12 13 14 15 data.drop([ ‘ Shenzhen ‘ , ‘ Guangzhou ‘ ]) one two three four Beijing 8 9 10 11 Shanghai 12 13 14 15 data.drop([ ‘ two ‘ ],axis=1) 删除第二列 2.函数映射   Numpy的 ufunc 也可以用于操作pandas对象。   例如:np.fabs(frame)      DataFrame.apply     DataFrame. apply ( func axis=0 broadcast=None raw=False reduce=None result_type=None args=() **kwds )

Pandas中DataFrame数据合并、连接(concat、merge、join)

匿名 (未验证) 提交于 2019-12-03 00:34:01
最近在工作中,遇到了数据合并、连接的问题,故整理如下,供需要者参考~ 一、concat:沿着一条轴,将多个对象堆叠到一起 concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, copy=True): df1=DataFrame(np.random.randn(3,4),columns=['a','b','c','d']) df2=DataFrame(np.random.randn(2,3),columns=['b','d','a']) pd.concat([df1,df2]) a b c d 0 -0.848557 -1.163877 -0.306148 -1.163944 1 1.358759 1.159369 -0.532110 2.183934 2 0.532117 0.788350 0.703752 -2.620643 0 -0.316156 -0.707832 NaN -0.416589 1 0.406830 1.345932 NaN -1.874817 pd.concat([df1,df2],ignore_index=True) a b c d 0 -0

pyecharts学习笔记

匿名 (未验证) 提交于 2019-12-03 00:26:01
中文官方文档: 点击打开链接 1.基本语法学习 from pyecharts import Bar bar = Bar("我的第一个图表", "这里是副标题") bar.add("服装", ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"], [5, 20, 36, 10, 75, 90]) # bar.print_echarts_options() # 该行只为了打印配置项,方便调试时使用 bar.render() # 生成本地 HTML 文件 add() : 主要方法,用于添加图表的数据和设置各种配置项 print_echarts_options() :打印输出图表的所有配置项 render(): 默认将会在根目录下生成一个 render.html 的文件,支持 path 参数,设置文件保存位置,如 render(r"e:\my_first_chart.html"),文件用浏览器打开。 Note : 可以按右边的下载按钮将图片下载到本地,如果想要提供更多实用工具按钮, 请在 add() 中设置 is_more_utils 为 True 2.使用主题 from pyecharts import Bar bar = Bar("我的第一个图表", "这里是副标题") bar.use_theme('dark') bar.add("服装", ["衬衫",

js中将字符串转型为时间类型

匿名 (未验证) 提交于 2019-12-03 00:22:01
转型时间类型 function dateParse(dateString){ var SEPARATOR_BAR = "-"; var SEPARATOR_SLASH = "/"; var SEPARATOR_DOT = "."; var dateArray; if(dateString.indexOf(SEPARATOR_BAR) > -1){ dateArray = dateString.split(SEPARATOR_BAR); }else if(dateString.indexOf(SEPARATOR_SLASH) > -1){ dateArray = dateString.split(SEPARATOR_SLASH); }else{ dateArray = dateString.split(SEPARATOR_DOT); } return new Date(dateArray[0], dateArray[1]-1, dateArray[2]); }; 获取当前月份的N个月份后的信息 获取给定月份的N个月份后的信息 文章来源: js中将字符串转型为时间类型

描述符

匿名 (未验证) 提交于 2019-12-03 00:13:02
一、概念: Python 中,通过使用描述符,可以让程序在引用一个对象属性时自定义要完成的工作。 本质上看,描述符就是一个类,只不过它定义了另一个类中属性的访问方式。 换句话说,一个类可以将属性全权委托给描述符类。 描述符类基于以下3个特殊方法: 二、描述符分两种 ①数据描述符:至少实现了 __get__()和__set__() class Foo: def __set__(selfsself,instance, value): print("set") def __get__(self, instance, owner): print("get") ②非数据描述符:没有实现__set__() class Foo: def __get__(self, instance, owner): print("get") 实例:   class Foo: def __get__(self, instance, owner): #这里的instance是实例对象b1,owner是类Bar print("===>get方法") return instance.__dict__['x'] def __set__(self, instance, value): #这里的instance是实例对象b1,value是传入的值 print("===>set方法") instance.__dict__['x

tushare 获取复权数据

匿名 (未验证) 提交于 2019-12-03 00:03:02
tushare 中获取股票历史信息的借口有好几个:tushare.get_hist_data(), tushare.get_h_data(),tushare.get_k_data(), 网络上关于这几个函数的介绍方法也很多,但是get_k_data 虽然开放了设置前复权,后复权,不复权的三种参数设置,然而函数内部却并没有真正实现,前复权的数据与不复权的数据一致;因此想要获取的复权数据需要使用tushare.pro_bar, 具体示例如下: df = ts . pro_bar ( ts_code = '603997.SH' , adj = 'qfq' , start_date = startdate , end_date = enddate ) 其中 adj 是设置复权的接口, none :不复权 qfq :前复权 hfq :后复权 了解更过关于pro_bar的用户可以直接使用help(ts.pro_bar) 来源:51CTO 作者: wjlwzl 链接:https://blog.csdn.net/wjlwzl/article/details/100797034

R:ggplot2数据可视化――基础知识

匿名 (未验证) 提交于 2019-12-02 23:59:01
# 获取ggplot2 最容易的就是下载整个tidyverse: install.packages("tidyverse") # 也可以选择只下载ggplot2: install.packages("ggplot2") # 或者下载GitHub上的开发者版本 # install.packages("devtools") devtools::install_github("tidyverse/ggplot2") library(ggplot2) ggplot(diamonds) #以diamonds数据集为例 #gg <- ggplot(df, aes(x=xcol, y=ycol)) 其中df只能是数据框 ggplot(diamonds, aes(x=carat)) # 如果只有X-axis值 Y-axis can be specified in respective geoms. ggplot(diamonds, aes(x=carat, y=price)) # if both X and Y axes are fixed for all layers. ggplot(diamonds, aes(x=carat, color=cut)) # 'cut' 变量每种类型单独一个颜色, once a geom is added. #aes代表美化格式 ggplot2 把 X 和 Y