Pandas timestamp difference in groupby transform

I have a dataframe with an integer index, session_id, event, and time_stamp that looks like this: In [41]: df = pd.DataFrame(data={'session_id': np.sort(np.random.choice(np.arange(3), 11)), 'event': np.random.choice(['A', 'B', 'C', 'D'], 11), 'time_...
more »

2017-02-15 22:02 (1) Answers

pandas: creating a dataframe from a dictionary

Take the dictionary: dict = {'a':'ham', 'b': 'ham', 'c': 'chicken', 'd': 'beef', 'e': 'chicken'} how do I take this dictionary and turn it into a dataframe where the values are the columns? i.e. I want a dataframe showing: ham chicken beef...
more »

2017-02-14 18:02 (2) Answers

Pandas improvement

I currently have a Pandas Dataframe in which I'm performing comparisons between columns. I found a case in which there are empty columns when comparison is taking place, comparison for some reason returns else value. I added an extra statement to cle...
more »

2017-02-14 10:02 (1) Answers

How to convert dataframe new format?

I have a dataframe : import pandas as pd df = pd.DataFrame({'cell': ['A1', 'A2', 'B1', 'A3', 'B2', 'B3', 'A4', 'B4'], 'site': ['A', 'A', 'B', 'A', 'B', 'B', 'A', 'B']}) >>> df cell site 0 A1 A 1 A2 A 2...
more »

2017-02-14 08:02 (3) Answers

how to clip pandas dataframe column-wise?

I have In [67]: a Out[67]: 0 1 2 0 1 2 3 1 4 5 6 when I run In [69]: a.clip(lower=[1.5,2.5,3.5],axis=1) I got ValueError: other must be the same shape as self when an ndarray Is that expected? I was expecting to get something lik...
more »

2017-02-14 05:02 (2) Answers

How to convert list to row dataframe with Pandas

I have a list of items like this: A = ['1', 'd', 'p', 'bab', ''] My goal is to convert such list into a dataframe of 1 row and 5 columns. If I type pd.DataFrame(A) I get 5 rows and 1 column. What should I do in order to get the result I want? ...
more »

2017-02-13 12:02 (1) Answers

How to groupby and transform in pandas

I have dataframe below A B C 1 1 a 1 2 b 1 3 c 2 4 d 2 5 e I would ilke to transform like below A B C 1 6 a 2 9 d B means the sum of group and C is the first elements in previous df How can I get this result ? ...
more »

2017-02-13 11:02 (1) Answers

Checking the equality of two dataframes

What's Pythonic way of Checking the equality of two dataframes? What I'm currently doing: Sorting the data frames by a column that has unique values with pandas.DataFrame.sort_values() Resetting the index after data frame is sorted using pandas.Da...
more »

2017-02-13 08:02 (2) Answers