Consider this Dataframe: This is the code to get values of column C, where it is the first row of each group (Column A): So first will be: (100, 200, 300). Now I want to add new column which it will be 1 if value of column C for row is in firsts otherwise it will be 0. A B
Tag: pandas
Pandas Dataframe – Shifting rows down and maintaining data
My original Dataframe (df): I want to shift the values down by 6 like so: When I use df = df.shift(6), I end up loosing data. I found this post (How to shift a column in Pandas DataFrame without losing value) but it only seems to work if the values are shifted down by 1. How can I shift multiple
Python: Datetime to season
I want to convert a date time series to season, for example for months 3, 4, 5 I want to replace them with 2 (spring); for months 6, 7, 8 I want to replace them with 3 (summer) etc. So, I have this series and this is the code I have been trying to use, but to no avail. and
Python and Matplotlib: characters as the x axis
Hi Stack Overflow community. I think I am trying to code the impossible with matplotlib, so if there is a different python library that will better suit me, please let me know! I have an entire amino acid sequence (Represented as capital letters in the image) of a protein (protein x). This will be my x axis. I have two
PermissionError: [Errno 13] Permission denied: ‘C:\Program Files\Python35\Lib\site-packages\six.py’
I am using python 3.5.3, and now I want to install pandas and numpy but not able to, following is the error in cmd, anyone can help me? Answer As others have pointed out you need to run the command with admin privileges. How to do this varies by windows version, but on Windows 8 and 10 you can just
Creating a dataframe from a dict where keys are tuples
I have the following dict, with keys as tuples: I’d like to create a dataframe with 3 columns: Col1, Col2 and Col3 which should look like this: I can’t figure out how to split the tuples other than parsing the dict pair by pair. Answer Construct a Series first, then resetting the index will give you a DataFrame: You can
Pandas – converting yes : no to True : False failing
My best efforts to convert a column with ‘yes’ ‘no’ values to True, False or 1 , 0 are failing. The column is ‘subscribed’. Tried the following. None of them worked: Answer As EdChum points out you need to assign back to the df. Input: Output:
Pythonic type hints with pandas?
Let’s take a simple function that takes a str and returns a dataframe: What is the recommended pythonic way of adding type hints to this function? If I ask python for the type of a DataFrame it returns pandas.core.frame.DataFrame. The following won’t work though, as it’ll tell me that pandas is not defined. Answer Why not just use pd.DataFrame? Result
PyInstaller with Pandas creates over 500 MB exe
I try to create an exe file using PyInstaller 3.2.1, for test purpose I tried to make an exe for following code: After considerable amount of time (15mins +) I finished with dist folder as big as 620 MB and build – 150 MB. I work on Windows using Python 3.5.2 |Anaconda custom (64-bit). Might be worth noting that in
Replacing values greater than a number in pandas dataframe
I have a large dataframe which looks as: I want to replace each element greater than 9 with 11. So, the desired output for above example is: Edit: My actual dataframe has about 20,000 rows and each row has list of size 2000. Is there a way to use numpy.minimum function for each row? I assume that it will be