Python Value Error: Duplicated level name: "variable", assigned to level 1, is already used for level 0 - python-3.x

I am using this below code for multiple charts visualization:
data.groupby(['y', 'y']).size().unstack().plot(kind='bar', stacked=True, ax=plt.subplot(6,2,2+1),figsize=(15,25))
But getting the following error:
Duplicated level name: "y", assigned to level 1, is already used for level 0.
whereas if I writing the same above code for other variable its working for example:
data.groupby(['otherObj', 'y']).size().unstack().plot(kind='bar', stacked=True, ax=plt.subplot(6,2,2+1),figsize=(15,25))
How can the above error be sorted?

Related

Octave boxwidth does not recognise core figure properties

I am trying to use the boxplot command in the statistics package, and it seems like most of the plot options are not recognised by Octave, by which I mean calling options like "BoxWidth" results in the following error:
error: set: unknown line property BoxWidth
error: __go_line__: unable to create graphics handle
error: called from
__plt__>__plt2vv__ at line 495 column 10
__plt__>__plt2__ at line 242 column 14
__plt__ at line 107 column 18
The code snippet producing this is as follows with the note that I have tried lower, upper,, camel, and sentence case for "BoxWidth" (documentation specifies camel case) and that I have tried both quotation marks and apostrophes to mark out the properties and the property options, with the same error produced in each case.
groups = [g_1, g_2, g_3, g_4, g_5, g_6, g_7, g_8, g_9, g_10, g_11];
data = [day_1_seat, day_2_seat, day_3_seat, day_4_seat, day_5_seat, ...
day_6_seat, day_7_seat, day_8_seat, day_9_seat, day_10_seat, ...
day_11_seat];
labels = {"29/07", "04/08", "05/08", "06/08", "07/08", "09/08", "11/08",...
"12/08", "13/08", "28/08", "01/09"};
s = boxplot(data,groups, "Notch", 0, "Symbol",".", "BoxWidth", "fixed");
The nature of the data in "groups" and "data" is unimportant, as I can create the boxplot without specifying properties without any issue. I have also tried specifying plot options after the initial call to boxplot with no luck.
This issue also occurs with other properties, such as Labels, OutlierTags etc, but not with "Notch" or "Symbol". I'm not a novice user, but I cannot figure out what the issue is here, any advice would be greatly appreciated!

Create a connection coming from a `spike_source_cell` in Arbor?

The docs specify that in order to create a connection a source and dest are required (of type cell_global_label and cell_local_label respectively). For connections between cable cells this works fine because you can place labels on their decor and then use those labels in the cell_global_label, but how do I connect from a spike_source_cell?
Here's what I do for cable cells:
arbor.connection(
arbor.cell_global_label(gid, "soma_spike_detector"),
arbor.cell_local_label("soma_synapse"),
1,
0.1
)
But since I can't create labels on a spike_source_cell it throws the following error:
RuntimeError: Model building error on cell 26: connection endpoint label "soma_spike_detector": label does not exist.
The docs on spike source cells mention:
has one built-in source, which needs to be given a label to be used when forming connections from the cell;
So you can use the label that you gave when constructing spike_source_cells as the label when constructing the cell_global_label:
# When constructing the source cell
arbor.spike_source_cell(
"spike_source",
arbor.explicit_schedule([5, 10, 12])
)
# In the recipe's `connections_on`:
arbor.connection(
arbor.cell_global_label(gid, "spike_source"),
arbor.cell_local_label("soma_synapse"),
1,
0.1
)

Funnel Chart in plotly

I am trying to create a funnel chart using plotly and am not having any luck. Even the canned examples from plotly don't work for me, can someone please help?
from plotly import graph_objects as go
fig = go.Figure(go.Funnel(
y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
x = [39, 27.4, 20.6, 11, 2]))
fig.show()
I get this huge traceback error:
lueError:
Invalid value of type 'plotly.graph_objs.Funnel' received for the 'data' property of
Received value: Funnel({
'x': [39, 27.4, 20.6, 11, 2],
'y': [Website visit, Downloads, Potential customers, Requested price, invoice
sent]
})
The 'data' property is a tuple of trace instances
that may be specified as:
- A list or tuple of trace instances
(e.g. [Scatter(...), Bar(...)])
- A list or tuple of dicts of string/value properties where:
- The 'type' property specifies the trace type
One of: ['area', 'bar', 'barpolar', 'box',
'candlestick', 'carpet', 'choropleth', 'cone',
'contour', 'contourcarpet', 'funnel',
'funnelarea', 'heatmap', 'heatmapgl',
'histogram', 'histogram2d',
'histogram2dcontour', 'isosurface', 'mesh3d',
'ohlc', 'parcats', 'parcoords', 'pie',
'pointcloud', 'sankey', 'scatter',
'scatter3d', 'scattercarpet', 'scattergeo',
'scattergl', 'scattermapbox', 'scatterpolar',
'scatterpolargl', 'scatterternary', 'splom',
'streamtube', 'sunburst', 'surface', 'table',
'violin', 'volume', 'waterfall']
- All remaining properties are passed to the constructor of
the specified trace type
(e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])
It seems like you’re using version 3, in which case you will need to use go.Figure(data=[go.Funnel(...)]) (basically wrap your funnel trace in an array... only in version 4 is this optional)

How do I declare and use a variable in the yaml file that is formatted for pyresttest?

So, a brief description of what I want, what my issue is, and what I have tried.
I want to declare and use a dictionary variable for my tests in pyrest, specifically for the [url, body] section so that I can conduct my POST tests targeting a specific endpoint and with a preformatted body.
Here is how mytest.yml file is structured:
- data:
- id: 63
- rate: 25
... a sizable set of field for reasons ...
- type: lab_test_authorization
- modified_at: ansible_date_time.datetime # Useful way to generate
- test:
- url: "some-valid-url/{the_url_question}" # data['special_key']
- method: 'POST'
- headers : {etc..etc}
- body: '{ "data": ${the_body_question} }' # data (the content)
Now the problem starts in my lack of understanding why (if true) does pyrest does not have support for dictionary mappings. I understand yaml supports these feature but am not sure if pyrest can parse through it. Knowing how to call and use dictionary variable in my url and body tags would be significantly helpful.
As of right now, if I try to convert my data Sequence into a data Dictionary, I will get an error stating:
yaml.parser.ParserError: while parsing a block mapping
in "<unicode string>", line 4, column 1:
data:
^
expected <block end>, but found '-'
in "<unicode string>", line 36, column 1:
- config:
I'm pretty sure there are gaps in my knowledge regarding how yaml and pyresttest interact with each other, so any insight would be greatly appreciated.

all arguments must have same length

The achievement variable has three different values. All N/A and null values have already been removed from the dataset. When I try to run the confusion matrix code I receive the error "all arguments must have the same length."
glm.fit=multinom(Achievement~Time.Played, data=thesis2)
summary(glm.fit)
predict(glm.fit, thesis2, "probs")
dim(thesis2)
set.seed(101)
train= thesis2[1:225928,]
test= thesis2[225929:451856,]
glm.fit=multinom(Achievement~Time.Played, data=train)
glm.predict=predict(glm.fit, test, "probs",na.action=na.omit)
dim(test)
dim(glm.predict)
length(glm.predict)
length(Achievement.test)
table(glm.predict,test$Achievement)
mean(glm.predict==Achievement.test)
----------
Error in table(glm.predict, test$Achievement) : all arguments must have the >same length
2. stop("all arguments must have the same length")
1.table(glm.predict, test$Achievement)
However the glm.predict has the dimensions 225928 6 and the test$Achievement has the dimensions 225928 3. I have looked at the other posts about the arguments not having the same length, and I can not figure out what is wrong with my code. Please help.

Resources