pandas

How can I get a previous row from where the condition is met in data frame in Pandas

无人久伴 提交于 2021-02-07 12:33:18
问题 For instance, I have a data frame below, I want to get the timestamp from the previous row where the Value is 1 TIME VALUE 0 23:01 0 1 23:02 0 2 23:03 1 3 23:04 0 4 23:05 0 5 23:06 1 6 23:07 0 7 23:08 0 8 23:09 0 9 23:10 0 10 23:11 1 11 23:12 0 12 23:13 0 13 23:14 0 14 23:15 0 15 23:16 1 I want to get the following as an output PREV_TIME 0 23:02 1 23:05 2 23:10 3 23:15 I don't know where to put shift(1) in the following PREV_TIME = df['Time'][(df.Value == 1)] 回答1: Call shift on 'VALUE' column

How can I get a previous row from where the condition is met in data frame in Pandas

僤鯓⒐⒋嵵緔 提交于 2021-02-07 12:32:52
问题 For instance, I have a data frame below, I want to get the timestamp from the previous row where the Value is 1 TIME VALUE 0 23:01 0 1 23:02 0 2 23:03 1 3 23:04 0 4 23:05 0 5 23:06 1 6 23:07 0 7 23:08 0 8 23:09 0 9 23:10 0 10 23:11 1 11 23:12 0 12 23:13 0 13 23:14 0 14 23:15 0 15 23:16 1 I want to get the following as an output PREV_TIME 0 23:02 1 23:05 2 23:10 3 23:15 I don't know where to put shift(1) in the following PREV_TIME = df['Time'][(df.Value == 1)] 回答1: Call shift on 'VALUE' column

Macbook m1 and python libraries [closed]

浪尽此生 提交于 2021-02-07 12:28:50
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 months ago . Improve this question Is new macbook m1 suitable for Data Science? Do Data Science python libraries such as pandas, numpy, sklearn etc work on the macbook m1 (Apple Silicon) chip and how fast compared to the previous generation intel based macbooks? 回答1: This GitHub repository has

Create combination of two pandas dataframes in two dimensions

爷,独闯天下 提交于 2021-02-07 12:28:01
问题 I have two pandas dataframes, df1 and df2. I want to create a dataframe df3 that contains all combinations using one column in df1 and one column in df2. The pseudocode of doing this inefficiently would be something like this: df3 = [] for i in df1: for j in df2: df3.append(i + j) # where i + j is the row with the combined cols from df1 and df2 Here's the format for df1: df1_id other_data_1 other_data_2 1 0 1 2 1 5 df2: df2_id other_data_3 other_data_4 1 0 1 3 2 2 And the goal is to get this

Create combination of two pandas dataframes in two dimensions

佐手、 提交于 2021-02-07 12:27:02
问题 I have two pandas dataframes, df1 and df2. I want to create a dataframe df3 that contains all combinations using one column in df1 and one column in df2. The pseudocode of doing this inefficiently would be something like this: df3 = [] for i in df1: for j in df2: df3.append(i + j) # where i + j is the row with the combined cols from df1 and df2 Here's the format for df1: df1_id other_data_1 other_data_2 1 0 1 2 1 5 df2: df2_id other_data_3 other_data_4 1 0 1 3 2 2 And the goal is to get this

Trouble converting string to float in python

偶尔善良 提交于 2021-02-07 12:23:41
问题 I am fairly new to Python so forgive me this simple question. I'm trying to convert string to float. Here is a sample of the data: 0 10.65% 1 7.90% When I try: df['int_rate'] = df['int_rate'].astype('float') I get: ValueError: could not convert string to float: '13.75%' When I try: df['int_rate'] = df['int_rate'].replace("%","", inplace=True) And check my data, I get: 0 None 1 None Any ideas what I'm doing wrong? Many thanks! 回答1: You can use Series.replace with parameter regex=True for

Python location, show distance from closest other location

佐手、 提交于 2021-02-07 12:14:36
问题 I am a location in a dataframe, underneath lat lon column names. I want to show how far that is from the lat lon of the nearest train station in a separate dataframe. So for example, I have a lat lon of (37.814563 144.970267), and i have a list as below of other geospatial points. I want to find the point that is closest and then find the distance between those points, as an extra column in the dataframe in suburbs. This is the example of the train dataset <bound method NDFrame.to_clipboard

Will passing ignore_index=True to pd.concat preserve index succession within dataframes that I'm concatenating?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 12:14:33
问题 I have two dataframes: df1 = value 0 a 1 b 2 c df2 = value 0 d 1 e I need to concatenate them across index, but I have to preserve the index of the first dataframe and continue it in the second dataframe, like this: result = value 0 a 1 b 2 c 3 d 4 e My guess is that pd.concat([df1, df2], ignore_index=True) will do the job. However, I'm worried that for large dataframes the order of the rows may be changed and I'll end up with something like this (first two rows changed indices): result =

Python location, show distance from closest other location

点点圈 提交于 2021-02-07 12:11:13
问题 I am a location in a dataframe, underneath lat lon column names. I want to show how far that is from the lat lon of the nearest train station in a separate dataframe. So for example, I have a lat lon of (37.814563 144.970267), and i have a list as below of other geospatial points. I want to find the point that is closest and then find the distance between those points, as an extra column in the dataframe in suburbs. This is the example of the train dataset <bound method NDFrame.to_clipboard

Python location, show distance from closest other location

狂风中的少年 提交于 2021-02-07 12:10:36
问题 I am a location in a dataframe, underneath lat lon column names. I want to show how far that is from the lat lon of the nearest train station in a separate dataframe. So for example, I have a lat lon of (37.814563 144.970267), and i have a list as below of other geospatial points. I want to find the point that is closest and then find the distance between those points, as an extra column in the dataframe in suburbs. This is the example of the train dataset <bound method NDFrame.to_clipboard