pandas

i get ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). using pandas

三世轮回 提交于 2021-02-05 09:39:41
问题 i get error while running this code what to do? i get error ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). unrealized = [0, 0.50, 0.90, 0.20, 3, 6, 7, 2] def stoploss(): df = pd.DataFrame({"price": unrealized}) df['high'] = df.cummax() if df['high'] <= 0.10: df['trailingstop'] = -0.50 df['signalstop'] = df['price'] < df['trailingstop'] if df['high'] >= 0.10: df['trailingstop'] = df['high'] - 0.10 df['signalstop'] = df['price'] < df[

i get ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). using pandas

本小妞迷上赌 提交于 2021-02-05 09:38:29
问题 i get error while running this code what to do? i get error ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). unrealized = [0, 0.50, 0.90, 0.20, 3, 6, 7, 2] def stoploss(): df = pd.DataFrame({"price": unrealized}) df['high'] = df.cummax() if df['high'] <= 0.10: df['trailingstop'] = -0.50 df['signalstop'] = df['price'] < df['trailingstop'] if df['high'] >= 0.10: df['trailingstop'] = df['high'] - 0.10 df['signalstop'] = df['price'] < df[

Array conditional must be same shape as self

我的未来我决定 提交于 2021-02-05 09:38:28
问题 I get this error when I attempt to compare to variable names such as: compare = Search1.where(Search1UK>Search1DE) compare compare.fillna(0) 'Search1UK' and 'Search1DE' are both variable names in which I have assigned a name to identify columns within different data frames. Anyone could help on this please? 回答1: try: compare = Search1.where(Search1['Search1UK']>Search1['Search1DE']) 来源: https://stackoverflow.com/questions/55163796/array-conditional-must-be-same-shape-as-self

Normalize a complex nested JSON file

心不动则不痛 提交于 2021-02-05 09:37:41
问题 Im trying to normalize the below json file into 4 tables - "content", "Modules", "Images" and "Everything Else in another table" { "id": "0000050a", "revision": 1580225050941, "slot": "product-description", "type": "E", "create_date": 1580225050941, "modified_date": 1580225050941, "creator": "Auto", "modifier": "Auto", "audit_info": { "date": 1580225050941, "source": "AutoService", "username": "Auto" }, "total_ID": 1, "name": "Auto_A1AM78C64UM0Y8_B07JCJR5HW", "content": [{ "ID": ["B01"],

Specify float_format differently for each column (scientific notation vs decimal precision)

依然范特西╮ 提交于 2021-02-05 09:34:07
问题 I have multiple columns, some I want in scientific notation, others to a specific level of decimal precision: Frequency n 0 0.0023 2.3 1 0.0420 4.5 2 0.5460 6.7 3 0.1230 8.9 Frequency can have small orders of magnitude, so I end up with a billion zeros. The 'n' column should have a set number of decimal places. I've attempted to do the following on the 'Frequency' column: fntables['Frequency'].options.display.float_format = '{:.2e}'.format This returns the expected error that "'Series' object

Convert a column of dates from ordinal numbers to the standard date format - pandas

假装没事ソ 提交于 2021-02-05 09:29:17
问题 I have to convert a column of dates from the integer/date format to the date format d-m-Y. Example: import pandas as pd col1 = [737346, 737346, 737346, 737346, 737059, 737346] col2 = ['cod1', 'cod2', 'cod3', 'cod4', 'cod1', 'cod2'] dict = {'V1' : col1, 'V2' : col2} df = pd.DataFrame.from_dict(dict) df V1 V2 0 737346 cod1 1 737346 cod2 2 737346 cod3 3 737346 cod4 4 737059 cod1 5 737346 cod2 expected: df V1 V2 0 14-10-2019 cod1 1 14-10-2019 cod2 2 14-10-2019 cod3 3 14-10-2019 cod4 4 31-12-2018

Why is Bokeh's plot not changing with plot selection?

被刻印的时光 ゝ 提交于 2021-02-05 09:29:17
问题 Struggling to understand why this bokeh visual will not allow me to change plots and see the predicted data. The plot and select (dropdown-looking) menu appears, but I'm not able to change the plot for items in the menu. Running Bokeh 1.2.0 via Anaconda. The code has been run both inside & outside of Jupyter. No errors display when the code is run. I've looked through the handful of SO posts relating to this same issue, but I've not been able to apply the same solutions successfully. I wasn't

Pandas - Finding percent contributed by each group

雨燕双飞 提交于 2021-02-05 09:26:18
问题 I am trying to find the percentage contribution made by each date group. Given below is how my data looks like. Expecting to find contribution of each product for a given date. date, product, quantity 2020-01, prod_a, 100 2020-01, prod_b, 200 2020-01, prod_c, 20 2020-01, prod_d, 50 2020-02, prod_a, 30 2020-02, prod_b, 30 2020-02, prod_c, 40 My expected output would be as below: date, product, quantity, prct_contributed 2020-01, prod_a, 100, 27% 2020-01, prod_b, 200, 54% 2020-01, prod_c, 20, 5

Pandas convert float to int if decimals are 0

两盒软妹~` 提交于 2021-02-05 08:56:11
问题 I have a pandas dataframe, in which some columns have numeric values while others don't, as shown below: City a b c Detroit 129 0.54 2,118.00 East 188 0.79 4,624.4712 Houston 154 0.65 3,492.1422 Los Angeles 266 1.00 7,426.00 Miami 26 0.11 792.18 MidWest 56 0.24 772.7813 I want to round off these numeric values to 2 decimal places, for which I am using: df = df.replace(np.nan, '', regex=True) After which df becomes: City a b c Detroit 129.0 0.54 2,118.0 East 188.0 0.79 4,624.47 Houston 154.0 0

Pandas convert float to int if decimals are 0

馋奶兔 提交于 2021-02-05 08:56:09
问题 I have a pandas dataframe, in which some columns have numeric values while others don't, as shown below: City a b c Detroit 129 0.54 2,118.00 East 188 0.79 4,624.4712 Houston 154 0.65 3,492.1422 Los Angeles 266 1.00 7,426.00 Miami 26 0.11 792.18 MidWest 56 0.24 772.7813 I want to round off these numeric values to 2 decimal places, for which I am using: df = df.replace(np.nan, '', regex=True) After which df becomes: City a b c Detroit 129.0 0.54 2,118.0 East 188.0 0.79 4,624.47 Houston 154.0 0