I have a dataframe like as shown below I would like to create 3 new columns val_num – will store ONLY NUMBER values that comes along with symbols ex: 1234 (from >1234) and 1000 (from <1000) but WILL NOT STORE 31 (from 31sadj) because it doesn’t have any symbol val_str – will store only…
Tag: pandas
Copy non-na rows to fill non-na columns using pandas
I have a dataframe like as shown below What I would like to do is copy non-na rows from Test column and paste it in corresponding row under sourcename column When I tried the below, it makes the other rows of sourcename column as NA I expect my output to be like as shown below Answer One idea with Series.fill…
Pandas update index on dataframe view
I have a multi-indexed (2 levels) pandas Dataframe called data. I create a view on a part of this dataframe with smalldata = data.loc[(slice(start,end),slice(None)),:]. If I display smalldata, it displays the data I expect. If I print smalldata.index, it shows the multi-index I expect based on the values I ch…
Pandas `hash_pandas_object` not producing duplicate hash values for duplicate entires
I have two dataframes, df1 and df2, and I know that df2 is a subset of df1. What I am trying to do is find the set difference between df1 and df2, such that df1 has only entries that are different from those in df2. To accomplish this, I first used pandas.util.hash_pandas_object on each of the dataframes, and…
I need to add specific rows in pandas DataFrame, at specific position
I’m currently working on a project and I need to add specific rows whenever the tagged sentence ends. Whenever the ‘N’ column equals 1 it means that a new sentence started. I want to add two rows for each sentence: a row with ‘Pos’= START at the beginning of the sentence, and a r…
How to sort a dataframe with the first occurences of each unique element in a column?
Dataframe is it is So i’d like to sort this df over the fehmi over the first occurences of the entries and they are grouped together then. The desired is because we saw trial first in df so we gather its entries together. Then we saw error so they are together and so on. I attempted with a groupby with
elegant way to replace multiple list of values with a multiple single value
I have a dataframe like as shown below I would like to replace a list of values like as shown below a) Replace P, PRIMARY,PRI with primary b) Replace S, SECONDARY, SEC with secondary c) Replace T, TERTIARY, THIRD with third I tried the below But is there any other efficient and elegant way to write this in a …
How to replace pandas plot xticks with days?
I’ve got a pandas hist plot like shown below. As you can see the xticks are currently set to 0-6 (Sunday – Saturday). I’d like to replace the tick label to the actual days so the days are showing instead of numbers. 0 – Sunday 1 – Monday 2 – Tuesday 3 – Wednesday . . …
Extract only cells containing a string from pandas table and copy them into a new table
I have a huge pandas table, with many rows and columns. I want to pull all the cells that contain a specific string and create a new table containing only those. Any ideas on how to approach this? Thank you! Answer Do you mean something like this?
Plot a bar plot by using Seaborn
I am new in data visualization. I am practicing Seaborn and I am trying to plot a barplot with this dataframe. I want the chart has 3 bars on each symbol, however, the output has only 1 bar on each symbol. May I know how to fix it? Part of the DataFrame… The code like this: Output like this: Answer