series

assessing if date time function in each row of df falls within range of date time in another df

こ雲淡風輕ζ 提交于 2020-07-21 04:26:14
问题 I am new to python, and need some help with a question I am having regarding the date time function. I have df_a which has a column titled time , and I am trying to create a new column id in this df_a . I want the id column to be determined by whether or not the time is contained within a range of times on df_b columns between "date" and "date_new", for example the first row has a date of "2019-01-07 20:52:41" and "date_new" of "2019-01-07 21:07:41" (a 15 minute time interval), I would like

How to solve the Attribute error 'float' object has no attribute 'split' in python?

佐手、 提交于 2020-07-09 03:07:25
问题 When I run the below code, it gives me an error saying that there is attribute error: 'float' object has no attribute 'split' in python. I would like to know why this error comes about. def text_processing(df): """""=== Lower case ===""" '''First step is to transform comments into lower case''' df['content'] = df['content'].apply(lambda x: " ".join(x.lower() for x in x.split() if x not in stop_words)) return df df = text_processing(df) The full traceback for the error: Traceback (most recent

How to solve the Attribute error 'float' object has no attribute 'split' in python?

大憨熊 提交于 2020-07-09 03:07:15
问题 When I run the below code, it gives me an error saying that there is attribute error: 'float' object has no attribute 'split' in python. I would like to know why this error comes about. def text_processing(df): """""=== Lower case ===""" '''First step is to transform comments into lower case''' df['content'] = df['content'].apply(lambda x: " ".join(x.lower() for x in x.split() if x not in stop_words)) return df df = text_processing(df) The full traceback for the error: Traceback (most recent

Getting a list of indices where pandas boolean series is True

好久不见. 提交于 2020-07-02 08:08:45
问题 I have a pandas series with boolean entries. I would like to get a list of indices where the values are True . For example the input pd.Series([True, False, True, True, False, False, False, True]) should yield the output [0,2,3,7] . I can do it with a list comprehension, but is there something cleaner or faster? 回答1: Using Boolean Indexing >>> s = pd.Series([True, False, True, True, False, False, False, True]) >>> s[s].index Int64Index([0, 2, 3, 7], dtype='int64') If need a np.array object,

Getting a list of indices where pandas boolean series is True

只谈情不闲聊 提交于 2020-07-02 08:08:44
问题 I have a pandas series with boolean entries. I would like to get a list of indices where the values are True . For example the input pd.Series([True, False, True, True, False, False, False, True]) should yield the output [0,2,3,7] . I can do it with a list comprehension, but is there something cleaner or faster? 回答1: Using Boolean Indexing >>> s = pd.Series([True, False, True, True, False, False, False, True]) >>> s[s].index Int64Index([0, 2, 3, 7], dtype='int64') If need a np.array object,

Getting a list of indices where pandas boolean series is True

纵饮孤独 提交于 2020-07-02 08:08:25
问题 I have a pandas series with boolean entries. I would like to get a list of indices where the values are True . For example the input pd.Series([True, False, True, True, False, False, False, True]) should yield the output [0,2,3,7] . I can do it with a list comprehension, but is there something cleaner or faster? 回答1: Using Boolean Indexing >>> s = pd.Series([True, False, True, True, False, False, False, True]) >>> s[s].index Int64Index([0, 2, 3, 7], dtype='int64') If need a np.array object,

Find a series in dataframe and replace it with original row

让人想犯罪 __ 提交于 2020-06-29 03:47:15
问题 I have below dataframe df but some D4 s with True was causing an issue in my custom ordering. Temporarily, I stored such rows in a list and turned those D4 values to False intentionally and sorted with my custom ordering. Index D1 D2 D3 D4 D5 0 8 5 0 False True 1 45 35 0 True False 2 35 10 1 False True 3 40 5 0 True False 4 12 10 5 False False 5 18 15 13 False True 6 25 15 5 True False 7 35 10 11 False True 8 95 50 0 False False hacked_rows = [] def hack_d4(row): if row['D3'] in [0, 1]: row[