Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Sign InSign Up

Softans

Softans Logo Softans Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Share & grow the world's knowledge!

We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.

Create A New Account
  • Recent Questions
  • Most Answered
  • Answers
  • Most Visited
  • Most Voted
  • No Answers


Softans post your question and answer here also read blogs at Blogger.com
Softans is made-up of two words "Software" and "Answer". Anyone can post their questions here. It's same as Stackoverflow Its new emerging platform for question and answer. Use Softans to ask questions related to any daily life's topics. Softans community is growing gradually .This platform is developed for question asking .Anyone can post here question here to get best answer.
Anyone can post here question here to get best answer

  1. Asked: May 23, 2022

    404 error for Google Tag Manager

    Jesson Holder
    Added an answer on May 23, 2022 at 5:30 am

    You need to publish a version of your container. If it is not published, the request will return a 404 error. To publish your current workspace: Click Submit at the top right hand side of the screen. The Submit Changes screen will appear, with options to publish the container and save a version of yRead more

    You need to publish a version of your container. If it is not published, the request will return a 404 error.

    To publish your current workspace:

    1. Click Submit at the top right hand side of the screen. The Submit Changes screen will appear, with options to publish the container and save a version of your container.
    2. Select Publish and Create Version if it is not already selected.
    3. Review the Workspace Changes section to see if your configuration appears as you expect.
    4. Enter a Version Name and Version Description.
    5. If you have Tag Manager configured to use multiple environments, use the Publish to Environment section to select which environment you’d like to publish to.
    6. Click Publish.
    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Asked: May 17, 2022

    Cypress: Test if element does not exist

    Best Answer
    David Smith
    Added an answer on May 17, 2022 at 1:05 pm

    Well this seems to work, so it tells me I have some more to learn about .should() cy.get('.check-box-sub-text').should('not.exist');

    Well this seems to work, so it tells me I have some more to learn about .should()

    cy.get('.check-box-sub-text').should('not.exist');
    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. Asked: May 17, 2022

    Update value while using byte offset and width numerically

    Jesson Holder
    Added an answer on May 17, 2022 at 9:14 am

    And I believe it means that we skip first 8 bites and then take 16 bits and then we add new value before it. I'm not 100% sure too –

    And I believe it means that we skip first 8 bites and then take 16 bits and then we add new value before it. I’m not 100% sure too
    –

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. Asked: May 17, 2022

    How to replace img tag with pitcure tag in summernote?

    Best Answer
    Charlis
    Added an answer on May 17, 2022 at 8:28 am

    You can create a picture tag straight from the string, that is obvously unsafe. const picture = $(`<picture> <source media="(min-width: 400px)" srcset="uploads/large/JS60y3eMKG.webp" type="image/webp"> <source media="(max-width: 300px)" srcset="uploads/medium/JS60y3eMKG.webp" type="imRead more

    You can create a picture tag straight from the string, that is obvously unsafe.

    const picture = $(`<picture>
        <source media="(min-width: 400px)" srcset="uploads/large/JS60y3eMKG.webp" type="image/webp">
        <source media="(max-width: 300px)" srcset="uploads/medium/JS60y3eMKG.webp" type="image/webp">
        <source media="(max-width: 200px)" srcset="uploads/small/JS60y3eMKG.webp" type="image/webp">
        <img src="uploads/small/JS60y3eMKG.webp" alt="test">
    </picture>`)
    

    And just insert it like you did with an image

    $('#summernote').summernote("insertNode", picture[0])

    It would be safer to split them into components.

    const picture = $('<picture>')
    const source1 = $('<source>').attr('srcset', url).attr('media', size)
    const source2 = $('<source>').attr('srcset', url).attr('media', size)
    const source3 = $('<source>').attr('srcset', url).attr('media', size)
    const img = $('<img>').attr('src', url)
    picture.append(source1, source2, source3, img)
    $('#summernote').summernote("insertNode", picture[0])
    

    Now you can iterate through your ajax response and dynamically create and add new source’s to a picture.

    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  5. Asked: May 17, 2022

    How can I pivot a dataframe?

    Jesson Holder
    Added an answer on May 17, 2022 at 7:26 am

    We start by answering the first question: Question 1 Why do I get ValueError: Index contains duplicate entries, cannot reshape This occurs because pandas is attempting to reindex either a columns or index object with duplicate entries. There are varying methods to use that can perform a pivot. SomeRead more

    We start by answering the first question:

    Question 1

    Why do I get ValueError: Index contains duplicate entries, cannot reshape

    This occurs because pandas is attempting to reindex either a columns or index object with duplicate entries. There are varying methods to use that can perform a pivot. Some of them are not well suited to when there are duplicates of the keys in which it is being asked to pivot on. For example. Consider pd.DataFrame.pivot. I know there are duplicate entries that share the row and col values:

    df.duplicated(['row', 'col']).any()
    
    True
    

    So when I pivot using

    df.pivot(index='row', columns='col', values='val0')
    

    I get the error mentioned above. In fact, I get the same error when I try to perform the same task with:

    df.set_index(['row', 'col'])['val0'].unstack()
    

    Here is a list of idioms we can use to pivot

    1. pd.DataFrame.groupby + pd.DataFrame.unstack
      • Good general approach for doing just about any type of pivot
      • You specify all columns that will constitute the pivoted row levels and column levels in one group by. You follow that by selecting the remaining columns you want to aggregate and the function(s) you want to perform the aggregation. Finally, you unstack the levels that you want to be in the column index.
    2. pd.DataFrame.pivot_table
      • A glorified version of groupby with more intuitive API. For many people, this is the preferred approach. And is the intended approach by the developers.
      • Specify row level, column levels, values to be aggregated, and function(s) to perform aggregations.
    3. pd.DataFrame.set_index + pd.DataFrame.unstack
      • Convenient and intuitive for some (myself included). Cannot handle duplicate grouped keys.
      • Similar to the groupby paradigm, we specify all columns that will eventually be either row or column levels and set those to be the index. We then unstack the levels we want in the columns. If either the remaining index levels or column levels are not unique, this method will fail.
    4. pd.DataFrame.pivot
      • Very similar to set_index in that it shares the duplicate key limitation. The API is very limited as well. It only takes scalar values for index, columns, values.
      • Similar to the pivot_table method in that we select rows, columns, and values on which to pivot. However, we cannot aggregate and if either rows or columns are not unique, this method will fail.
    5. pd.crosstab
      • This a specialized version of pivot_table and in its purest form is the most intuitive way to perform several tasks.
    6. pd.factorize + np.bincount
      • This is a highly advanced technique that is very obscure but is very fast. It cannot be used in all circumstances, but when it can be used and you are comfortable using it, you will reap the performance rewards.
    7. pd.get_dummies + pd.DataFrame.dot
      • I use this for cleverly performing cross tabulation.

    Examples

    What I’m going to do for each subsequent answer and question is to answer it using pd.DataFrame.pivot_table. Then I’ll provide alternatives to perform the same task.

    Question 3

    How do I pivot df such that the col values are columns, row values are the index, mean of val0 are the values, and missing values are 0?

    • pd.DataFrame.pivot_table
      • fill_value is not set by default. I tend to set it appropriately. In this case I set it to 0. Notice I skipped question 2 as it’s the same as this answer without the fill_value
      • aggfunc='mean' is the default and I didn’t have to set it. I included it to be explicit.
            df.pivot_table(
                values='val0', index='row', columns='col',
                fill_value=0, aggfunc='mean')
        
            col   col0   col1   col2   col3  col4
            row
            row0  0.77  0.605  0.000  0.860  0.65
            row2  0.13  0.000  0.395  0.500  0.25
            row3  0.00  0.310  0.000  0.545  0.00
            row4  0.00  0.100  0.395  0.760  0.24
        
    • pd.DataFrame.groupby
        df.groupby(['row', 'col'])['val0'].mean().unstack(fill_value=0)
      
    • pd.crosstab
        pd.crosstab(
            index=df['row'], columns=df['col'],
            values=df['val0'], aggfunc='mean').fillna(0)
      

    Question 4

    Can I get something other than mean, like maybe sum?

    • pd.DataFrame.pivot_table
        df.pivot_table(
            values='val0', index='row', columns='col',
            fill_value=0, aggfunc='sum')
      
        col   col0  col1  col2  col3  col4
        row
        row0  0.77  1.21  0.00  0.86  0.65
        row2  0.13  0.00  0.79  0.50  0.50
        row3  0.00  0.31  0.00  1.09  0.00
        row4  0.00  0.10  0.79  1.52  0.24
      
    • pd.DataFrame.groupby
        df.groupby(['row', 'col'])['val0'].sum().unstack(fill_value=0)
      
    • pd.crosstab
        pd.crosstab(
            index=df['row'], columns=df['col'],
            values=df['val0'], aggfunc='sum').fillna(0)
      

    Question 5

    Can I do more that one aggregation at a time?

    Notice that for pivot_table and crosstab I needed to pass list of callables. On the other hand, groupby.agg is able to take strings for a limited number of special functions. groupby.agg would also have taken the same callables we passed to the others, but it is often more efficient to leverage the string function names as there are efficiencies to be gained.

    • pd.DataFrame.pivot_table
        df.pivot_table(
            values='val0', index='row', columns='col',
            fill_value=0, aggfunc=[np.size, np.mean])
      
             size                      mean
        col  col0 col1 col2 col3 col4  col0   col1   col2   col3  col4
        row
        row0    1    2    0    1    1  0.77  0.605  0.000  0.860  0.65
        row2    1    0    2    1    2  0.13  0.000  0.395  0.500  0.25
        row3    0    1    0    2    0  0.00  0.310  0.000  0.545  0.00
        row4    0    1    2    2    1  0.00  0.100  0.395  0.760  0.24
      
    • pd.DataFrame.groupby
        df.groupby(['row', 'col'])['val0'].agg(['size', 'mean']).unstack(fill_value=0)
      
    • pd.crosstab
        pd.crosstab(
            index=df['row'], columns=df['col'],
            values=df['val0'], aggfunc=[np.size, np.mean]).fillna(0, downcast='infer')
      

    Question 6

    Can I aggregate over multiple value columns?

    • pd.DataFrame.pivot_table we pass values=['val0', 'val1'] but we could’ve left that off completely
        df.pivot_table(
            values=['val0', 'val1'], index='row', columns='col',
            fill_value=0, aggfunc='mean')
      
              val0                             val1
        col   col0   col1   col2   col3  col4  col0   col1  col2   col3  col4
        row
        row0  0.77  0.605  0.000  0.860  0.65  0.01  0.745  0.00  0.010  0.02
        row2  0.13  0.000  0.395  0.500  0.25  0.45  0.000  0.34  0.440  0.79
        row3  0.00  0.310  0.000  0.545  0.00  0.00  0.230  0.00  0.075  0.00
        row4  0.00  0.100  0.395  0.760  0.24  0.00  0.070  0.42  0.300  0.46
      
    • pd.DataFrame.groupby
        df.groupby(['row', 'col'])['val0', 'val1'].mean().unstack(fill_value=0)
      

    Question 7

    Can Subdivide by multiple columns?

    • pd.DataFrame.pivot_table
        df.pivot_table(
            values='val0', index='row', columns=['item', 'col'],
            fill_value=0, aggfunc='mean')
      
        item item0             item1                         item2
        col   col2  col3  col4  col0  col1  col2  col3  col4  col0   col1  col3  col4
        row
        row0  0.00  0.00  0.00  0.77  0.00  0.00  0.00  0.00  0.00  0.605  0.86  0.65
        row2  0.35  0.00  0.37  0.00  0.00  0.44  0.00  0.00  0.13  0.000  0.50  0.13
        row3  0.00  0.00  0.00  0.00  0.31  0.00  0.81  0.00  0.00  0.000  0.28  0.00
        row4  0.15  0.64  0.00  0.00  0.10  0.64  0.88  0.24  0.00  0.000  0.00  0.00
      
    • pd.DataFrame.groupby
        df.groupby(
            ['row', 'item', 'col']
        )['val0'].mean().unstack(['item', 'col']).fillna(0).sort_index(1)
      

    Question 8

    Can Subdivide by multiple columns?

    • pd.DataFrame.pivot_table
        df.pivot_table(
            values='val0', index=['key', 'row'], columns=['item', 'col'],
            fill_value=0, aggfunc='mean')
      
        item      item0             item1                         item2
        col        col2  col3  col4  col0  col1  col2  col3  col4  col0  col1  col3  col4
        key  row
        key0 row0  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.86  0.00
             row2  0.00  0.00  0.37  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.50  0.00
             row3  0.00  0.00  0.00  0.00  0.31  0.00  0.81  0.00  0.00  0.00  0.00  0.00
             row4  0.15  0.64  0.00  0.00  0.00  0.00  0.00  0.24  0.00  0.00  0.00  0.00
        key1 row0  0.00  0.00  0.00  0.77  0.00  0.00  0.00  0.00  0.00  0.81  0.00  0.65
             row2  0.35  0.00  0.00  0.00  0.00  0.44  0.00  0.00  0.00  0.00  0.00  0.13
             row3  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.28  0.00
             row4  0.00  0.00  0.00  0.00  0.10  0.00  0.00  0.00  0.00  0.00  0.00  0.00
        key2 row0  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.40  0.00  0.00
             row2  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.13  0.00  0.00  0.00
             row4  0.00  0.00  0.00  0.00  0.00  0.64  0.88  0.00  0.00  0.00  0.00  0.00
      
    • pd.DataFrame.groupby
        df.groupby(
            ['key', 'row', 'item', 'col']
        )['val0'].mean().unstack(['item', 'col']).fillna(0).sort_index(1)
      
    • pd.DataFrame.set_index because the set of keys are unique for both rows and columns
        df.set_index(
            ['key', 'row', 'item', 'col']
        )['val0'].unstack(['item', 'col']).fillna(0).sort_index(1)
      

    Question 9

    Can I aggregate the frequency in which the column and rows occur together, aka “cross tabulation”?

    • pd.DataFrame.pivot_table
        df.pivot_table(index='row', columns='col', fill_value=0, aggfunc='size')
      
            col   col0  col1  col2  col3  col4
        row
        row0     1     2     0     1     1
        row2     1     0     2     1     2
        row3     0     1     0     2     0
        row4     0     1     2     2     1
      
    • pd.DataFrame.groupby
        df.groupby(['row', 'col'])['val0'].size().unstack(fill_value=0)
      
    • pd.crosstab
        pd.crosstab(df['row'], df['col'])
      
    • pd.factorize + np.bincount
        # get integer factorization `i` and unique values `r`
        # for column `'row'`
        i, r = pd.factorize(df['row'].values)
        # get integer factorization `j` and unique values `c`
        # for column `'col'`
        j, c = pd.factorize(df['col'].values)
        # `n` will be the number of rows
        # `m` will be the number of columns
        n, m = r.size, c.size
        # `i * m + j` is a clever way of counting the
        # factorization bins assuming a flat array of length
        # `n * m`.  Which is why we subsequently reshape as `(n, m)`
        b = np.bincount(i * m + j, minlength=n * m).reshape(n, m)
        # BTW, whenever I read this, I think 'Bean, Rice, and Cheese'
        pd.DataFrame(b, r, c)
      
              col3  col2  col0  col1  col4
        row3     2     0     0     1     0
        row2     1     2     1     0     2
        row0     1     0     1     2     1
        row4     2     2     0     1     1
      
    • pd.get_dummies
        pd.get_dummies(df['row']).T.dot(pd.get_dummies(df['col']))
      
              col0  col1  col2  col3  col4
        row0     1     2     0     1     1
        row2     1     0     2     1     2
        row3     0     1     0     2     0
        row4     0     1     2     2     1
      

    Question 10

    How do I convert a DataFrame from long to wide by pivoting on ONLY two columns?

    • DataFrame.pivot

      The first step is to assign a number to each row – this number will be the row index of that value in the pivoted result. This is done using GroupBy.cumcount:

        df2.insert(0, 'count', df2.groupby('A').cumcount())
        df2
      
           count  A   B
        0      0  a   0
        1      1  a  11
        2      2  a   2
        3      3  a  11
        4      0  b  10
        5      1  b  10
        6      2  b  14
        7      0  c   7
      

      The second step is to use the newly created column as the index to call DataFrame.pivot.

        df2.pivot(*df2)
        # df2.pivot(index='count', columns='A', values='B')
      
        A         a     b    c
        count
        0       0.0  10.0  7.0
        1      11.0  10.0  NaN
        2       2.0  14.0  NaN
        3      11.0   NaN  NaN
      
    • DataFrame.pivot_table

      Whereas DataFrame.pivot only accepts columns, DataFrame.pivot_table also accepts arrays, so the GroupBy.cumcount can be passed directly as the index without creating an explicit column.

        df2.pivot_table(index=df2.groupby('A').cumcount(), columns='A', values='B')
      
        A         a     b    c
        0       0.0  10.0  7.0
        1      11.0  10.0  NaN
        2       2.0  14.0  NaN
        3      11.0   NaN  NaN
      

    Question 11

    How do I flatten the multiple index to single index after pivot

    If columns type object with string join

    df.columns = df.columns.map('|'.join)
    

    else format

    df.columns = df.columns.map('{0[0]}|{0[1]}'.format)
    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  6. Asked: May 12, 2022

    Search Bar Is Not In Coded Position HTML

    Charlis
    Added an answer on May 12, 2022 at 6:50 am
    This answer was edited.

    <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> * {box-sizing: border-box;} body { margin: 0; font-family: Arial, Helvetica, sans-serif; } .topnav { overflow: hidden; background-color: #e9e9e9; } .topnav a { floRead more

    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    * {box-sizing: border-box;}
    
    body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    }
    
    .topnav {
    overflow: hidden;
    background-color: #e9e9e9;
    }
    
    .topnav a {
    float: left;
    display: block;
    color: black;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-size: 17px;
    }
    
    .topnav a:hover {
    background-color: #ddd;
    color: black;
    }
    
    .topnav a.active {
    background-color: #2196F3;
    color: white;
    }
    
    .topnav input[type=text] {
    float: right;
    padding: 6px;
    margin-top: 8px;
    margin-right: 16px;
    border: none;
    font-size: 17px;
    }
    
    @media screen and (max-width: 600px) {
    .topnav a, .topnav input[type=text] {
    float: none;
    display: block;
    text-align: left;
    width: 100%;
    margin: 0;
    padding: 14px;
    }
    
    .topnav input[type=text] {
    border: 1px solid #ccc; 
    }
    }
    </style>
    </head>
    <body>
    
    <div class="topnav">
    <a class="active" href="#home">Home</a>
    <a href="#about">About</a>
    <a href="#contact">Contact</a>
    <input type="text" placeholder="Search..">
    </div>
    
    <div style="padding-left:16px">
    <h2>Responsive Search Bar</h2>
    <p>Navigation bar with a search box inside of it.</p>
    <p>Resize the browser window to see the responsive effect.</p>
    <p>For more examples on how to add a submit button and icon inside the search bar, go back to the tutorial.</p>
    </div>
    
    </body>
    </html>
    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  7. Asked: May 12, 2022

    How to iterate each row according to values of row above?

    Best Answer
    Charlis
    Added an answer on May 12, 2022 at 6:46 am

    The job essentially seems to be filling missing values by a previous value if such value exists at that measurement for each climber, so groupby.ffill should do the job: out = df[['Name']].join(df.groupby('Name').ffill()) Output: Name Timestamp Category Body Temp Altitude Heart Rate 0 Cody 08:10:23Read more

    The job essentially seems to be filling missing values by a previous value if such value exists at that measurement for each climber, so groupby.ffill should do the job:

    out = df[['Name']].join(df.groupby('Name').ffill())
    

    Output:

         Name Timestamp    Category  Body Temp  Altitude  Heart Rate
    0    Cody  08:10:23   Body Temp       35.9       NaN         NaN
    1  Dustin  08:12:58    Altitude        NaN       7.0         NaN
    2  Dustin  08:15:02  Heart Rate        NaN       7.0        75.0
    3    Cody  08:19:43   Body Temp       36.2       NaN         NaN
    4    Ryan  08:21:00  Heart Rate        NaN       NaN        71.0
    5  Dustin  08:30:17  Heart Rate        NaN       7.0        69.0
    6    Ryan  08:34:01    Altitude        NaN      12.0        71.0
    7    Cody  08:34:59    Altitude       36.2       6.0         NaN
    See less
    • 0
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
Load More Answers

Sidebar

Ask A Question

Recent Jobs

  • 9t5

    Jobs in Lahore

    • Anywhere
    • 9t5
    • Full Time
  • DPL

    Latest Jobs at DPL

    • Multiple
    • DPL
  • Smedia

    QA Consultant (Remote Job)

    • Remote
    • Smedia
  • Popular
  • Answers
  • Ghulam Nabi

    Why are the British confused about us calling bread rolls ...

    • 5 Answers
  • Alex

    application has failed to start because no appropriate graphics hardware ...

    • 4 Answers
  • Ghulam Nabi

    Is this statement, “i see him last night” can be ...

    • 4 Answers
  • Jesson Holder
    Jesson Holder added an answer You need to publish a version of your container. If it is… May 23, 2022 at 5:30 am
  • David Smith
    David Smith added an answer Well this seems to work, so it tells me I… May 17, 2022 at 1:05 pm
  • Jesson Holder
    Jesson Holder added an answer And I believe it means that we skip first 8… May 17, 2022 at 9:14 am

Trending Tags

android cypress flutter java javascript language python selenium typescript ubuntu

Top Members

Robert

Robert

  • 3 Questions
  • 1k Points
Luci

Luci

  • 5 Questions
  • 1k Points
Kevin O Brien

Kevin O Brien

  • 2 Questions
  • 1k Points

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Softans

Softans is a social questions & Answers Engine which will help you establish your community and connect with other people.

About Us

  • Blog
  • Jobs
  • About Us
  • Meet The Team
  • Contact Us

Legal Stuff

Help

Follow

© 2021 Softans. All Rights Reserved
With Love by Softans.