Error creating a new column using a library - python

I am trying to create a new column in existing dataframe using a library.Following is the error i am getting.
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
(https://i.stack.imgur.com/b47j8.png)
I tried adding a new column to calculate the implied volatility of ATM options
Link to library documentation http://vollib.org/documentation/python/1.0.2/apidoc/py_vollib.black_scholes.html

Related

Pandas.. does quantile function need sorted data to calculate percentiles?

I'm using Pandas to clean up some data and do basic statistics. I am wondering if quantile() does sort the values before the calculation or i must do the sorting beforehand?
For example, here I'm trying to get the 50th percentile of the number of workers in each company
Percentile50th = Y2015_df.groupby (["company"])["worker"].quantile(0.50)
I'm asking because when I was verifying the values I got with the results in MS Excel, I discovered that Median function requires the data to be sorted in order to get the right median. But I'm not sure if its the case in Pandas.
You do not need to sort. See the link in my previous comment. Example

Add data to Dataframe with pandas

I want to add a result from a simulation model to an existing dataframe at a specific position with the dataframe.
Based on a dataframe and model for linear regression I am calculating a value. This value must be added to the input dataframe used for the linear regression. I am using pandas insert functions which brings the following error:
enter image description here
Thank you very much for you help. It worked with:
X_heute_10 = df2.insert(4, 'Stunde_10', y_heute_10[0,0])

interact ipywidget min and max

I would like to set a min and max value for interact from ipywidgets.
This is all I could find concerning the use of interact. I am essentially trying to do the first example, however with a specified range of values for the slider.
The answer to your question is further down in the docs. Quoting the example for setting up min/max:
interact(f, x=widgets.IntSlider(min=-10,max=30,step=1,value=10))

pandas pct_change returns wrong value when sorting by column

I cannot get my pandas dataframe to correctly put an output for pct_change() using the code as follows.
for column in df:
print(df[column].pct_change())
However if I use the simple one line below there is no issue
print(df.pct_change())
If this issue is similar to pandas pct_change() function returning wrong value however the solution there involves updating numexpr and reinstall conda. I have done both and I dont understand why it would be an environment issue and not a code issue... So,
I am wondering why I would get different results when applying a column by column pct_change()?

How to remove multi indexing from a pandas pivot table for easy visualisation

When creating pivot tables there is often multi level indexing (two or more levels of index which show up as columns.
In these cases the object that the pivot function returns is still a dataframe but to my limited knowledge it is difficult to chart in this multi index form.
How do you go from a pivot table where you get the counts of one column line industry to putting that into a histogram with a charting library like plotly or d3 or bokeh or pygal or searborn without extracting series out of the pivot dataframe and creating a new dataframe with just one column index specifically for the visualisation.
Vamsi I tried reset the index multiple times on my industry pivot table example (above) and no matter how many times I reset the index I'm still left with a dataframe which has a multi index which makes it hard for me to graph/chart.

Categories

Resources