pandas

Huge proglem to load Plotly plots in Jupyter Notebook Python

放肆的年华 提交于 2021-02-08 10:37:23
问题 I have a huge problem with Jupyter Notebook. When he builds graphs using the plot packet, to display the next graph I have to reload the dataset, otherwise an error pops up: TypeError: list indices must be integers or slices , not str. When I reopen the project, all the graphs created using Plotly are not visible, just a white background and I have to reload them if I want to see them, and everything after reloading the dataset, that is: 1) I open the project in Jupyte Notebook, all graphs

Huge proglem to load Plotly plots in Jupyter Notebook Python

我与影子孤独终老i 提交于 2021-02-08 10:37:20
问题 I have a huge problem with Jupyter Notebook. When he builds graphs using the plot packet, to display the next graph I have to reload the dataset, otherwise an error pops up: TypeError: list indices must be integers or slices , not str. When I reopen the project, all the graphs created using Plotly are not visible, just a white background and I have to reload them if I want to see them, and everything after reloading the dataset, that is: 1) I open the project in Jupyte Notebook, all graphs

Efficiently calculating point of control with pandas

馋奶兔 提交于 2021-02-08 10:35:13
问题 My algorithm stepped up from 35 seconds to 15 minutes runtime when implementing this feature over a daily timeframe. The algo retrieves daily history in bulk and iterates over a subset of the dataframe (from t0 to tX where tX is the current row of iteration). It does this to emulate what would happen during the real time operations of the algo. I know there are ways of improving it by utilizing memory between frame calculations but I was wondering if there was a more pandas-ish implementation

What is the difference between math.isnan ,numpy.isnan and pandas.isnull in python 3?

元气小坏坏 提交于 2021-02-08 10:34:22
问题 A NaN of type decimal.Decimal causes: math.isnan to return True numpy.isnan to throw a TypeError exception. pandas.isnull to return False What is the difference between math.isnan, numpy.isnan and pandas.isnull? 回答1: The only difference between math.isnan and numpy.isnan is that numpy.isnan can handle lists, arrays, tuples whereas math.isnan can ONLY handle single integers or floats. However , I suggest using math.isnan when you just want to check if a number is nan because numpy takes

Remove duplicates based on the content of two columns not the order

拈花ヽ惹草 提交于 2021-02-08 10:33:47
问题 I have a correlation matrix that i melted into a dataframe so now i have the following for example: First Second Value A B 0.5 B A 0.5 A C 0.2 i want to delete only one of the first two rows. What would be the way to do it? 回答1: Use: #if want select columns by columns names m = ~pd.DataFrame(np.sort(df[['First','Second']], axis=1)).duplicated() #if want select columns by positons #m = ~pd.DataFrame(np.sort(df.iloc[:,:2], axis=1)).duplicated() print (m) 0 True 1 False 2 True dtype: bool df =

Remove duplicates based on the content of two columns not the order

丶灬走出姿态 提交于 2021-02-08 10:32:22
问题 I have a correlation matrix that i melted into a dataframe so now i have the following for example: First Second Value A B 0.5 B A 0.5 A C 0.2 i want to delete only one of the first two rows. What would be the way to do it? 回答1: Use: #if want select columns by columns names m = ~pd.DataFrame(np.sort(df[['First','Second']], axis=1)).duplicated() #if want select columns by positons #m = ~pd.DataFrame(np.sort(df.iloc[:,:2], axis=1)).duplicated() print (m) 0 True 1 False 2 True dtype: bool df =

What is the difference between math.isnan ,numpy.isnan and pandas.isnull in python 3?

寵の児 提交于 2021-02-08 10:31:02
问题 A NaN of type decimal.Decimal causes: math.isnan to return True numpy.isnan to throw a TypeError exception. pandas.isnull to return False What is the difference between math.isnan, numpy.isnan and pandas.isnull? 回答1: The only difference between math.isnan and numpy.isnan is that numpy.isnan can handle lists, arrays, tuples whereas math.isnan can ONLY handle single integers or floats. However , I suggest using math.isnan when you just want to check if a number is nan because numpy takes

Applying interpolation on DataFrame based on another DataFrame

南笙酒味 提交于 2021-02-08 10:30:52
问题 I have a DataFrame on which I would like to somehow add new columns based on the value of a specific column, whose result depends on data contained in another DataFrame . More specifically, I have df_original = Crncy Spread Duration 0 EUR 100 1.2 1 nan nan nan 2 100 3.46 3 CHF 200 2.5 4 USD 50 5.0 ... df_interpolation = CRNCY TENOR Adj_EUR Adj_USD 0 EUR 1 10 20 1 EUR 2 20 30 2 EUR 5 30 40 3 EUR 7 40 50 ... 10 CHF 1 50 10 11 CHF 2 60 20 12 CHF 5 70 30 ... and would now like to add the columns

Applying interpolation on DataFrame based on another DataFrame

巧了我就是萌 提交于 2021-02-08 10:29:10
问题 I have a DataFrame on which I would like to somehow add new columns based on the value of a specific column, whose result depends on data contained in another DataFrame . More specifically, I have df_original = Crncy Spread Duration 0 EUR 100 1.2 1 nan nan nan 2 100 3.46 3 CHF 200 2.5 4 USD 50 5.0 ... df_interpolation = CRNCY TENOR Adj_EUR Adj_USD 0 EUR 1 10 20 1 EUR 2 20 30 2 EUR 5 30 40 3 EUR 7 40 50 ... 10 CHF 1 50 10 11 CHF 2 60 20 12 CHF 5 70 30 ... and would now like to add the columns

Vectorizing an iterative function on Pandas DataFrame

 ̄綄美尐妖づ 提交于 2021-02-08 10:26:06
问题 I have a dataframe where the first row is the initial condition. df = pd.DataFrame({"Year": np.arange(4), "Pop": [0.4] + [np.nan]* 3}) and a function f(x,r) = r*x*(1-x) , where r = 2 is a constant and 0 <= x <= 1 . I want to produce the following dataframe by applying the function to column Pop row-by-row iteratively. I.e., df.Pop[i] = f(df.Pop[i-1], r=2) df = pd.DataFrame({"Year": np.arange(4), "Pop": [0.4, 0.48, 4992, 0.49999872]}) Question: Is it possible to do this in a vectorized way? I