Most Popular

1500 questions
1358
votes
32 answers

Create a Pandas Dataframe by appending one row at a time

How do I create an empty DataFrame, then add rows, one by one? I created an empty DataFrame: df = pd.DataFrame(columns=('lib', 'qty1', 'qty2')) Then I can add a new row at the end and fill a single field with: df = df._set_value(index=len(df),…
PhE
  • 15,656
  • 4
  • 23
  • 21
1357
votes
12 answers

Remove a git commit which has not been pushed

I did a git commit but I have not pushed it to the repository yet. So when I do git status, I get '# Your branch is ahead of 'master' by 1 commit. So if I want to roll back my top commit, can I just do: git reset --hard…
hap497
  • 154,439
  • 43
  • 83
  • 99
1356
votes
12 answers

What does the 'b' character do in front of a string literal?

Apparently, the following is the valid syntax: b'The string' I would like to know: What does this b character in front of the string mean? What are the effects of using it? What are appropriate situations to use it? I found a related question…
Jesse Webb
  • 43,135
  • 27
  • 106
  • 143
1355
votes
13 answers

How do I trim whitespace from a string?

How do I remove leading and trailing whitespace from a string in Python? " Hello world " --> "Hello world" " Hello world" --> "Hello world" "Hello world " --> "Hello world" "Hello world" --> "Hello world"
robert
1355
votes
15 answers

How to get the identity of an inserted row?

How am I supposed to get the IDENTITY of an inserted row? I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY, but don't understand the implications or impacts attached to each. Can someone please explain the differences and when I would be…
Oded
  • 489,969
  • 99
  • 883
  • 1,009
1355
votes
37 answers

How to remove item from array by value?

Is there a method to remove an item from a JavaScript array? Given an array: var ary = ['three', 'seven', 'eleven']; I would like to do something like: removeItem('seven', ary); I've looked into splice() but that only removes by the position…
MacMac
  • 34,294
  • 55
  • 151
  • 222
1355
votes
7 answers

What are some examples of commonly used practices for naming git branches?

I've been using a local git repository interacting with my group's CVS repository for several months, now. I've made an almost neurotic number of branches, most of which have thankfully merged back into my trunk. But naming is starting to become…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
1354
votes
8 answers

How to uncommit my last commit in Git

How can I uncommit my last commit in git? Is it git reset --hard HEAD or git reset --hard HEAD^ ?
richard
  • 13,881
  • 3
  • 18
  • 9
1354
votes
21 answers

How to deal with SettingWithCopyWarning in Pandas

Background I just upgraded my Pandas from 0.11 to 0.13.0rc1. Now, the application is popping out many new warnings. One of them like this: E:\FinReporter\FM_EXT.py:449: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a…
1353
votes
29 answers

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

I'm running a PHP script and continue to receive errors like: Notice: Undefined variable: my_variable_name in C:\wamp\www\mypath\index.php on line 10 Notice: Undefined index: my_index C:\wamp\www\mypath\index.php on line 11 Warning: Undefined array…
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
1353
votes
15 answers

jQuery document.createElement equivalent?

I'm refactoring some old JavaScript code and there's a lot of DOM manipulation going on. var d = document; var odv = d.createElement("div"); odv.style.display = "none"; this.OuterDiv = odv; var t = d.createElement("table"); t.cellSpacing =…
Rob Stevenson-Leggett
  • 35,279
  • 21
  • 87
  • 141
1353
votes
44 answers

How do I create a constant in Python?

How do I declare a constant in Python? In Java, we do: public static final String CONST_NAME = "Name";
zfranciscus
  • 16,175
  • 10
  • 47
  • 53
1352
votes
10 answers

How can I do a line break (line continuation) in Python?

Given: e = 'a' + 'b' + 'c' + 'd' How do I write the above in two lines? e = 'a' + 'b' + 'c' + 'd'
Ray
  • 187,153
  • 97
  • 222
  • 204
1352
votes
11 answers

Git merge hotfix branch into feature branch

Let’s say we have the following situation in Git: A created repository: mkdir GitTest2 cd GitTest2 git init Some modifications in the master take place and get committed: echo "On Master" > file git commit -a -m "Initial commit" Feature1 branched…
theomega
  • 31,591
  • 21
  • 89
  • 127
1351
votes
15 answers

How can I merge two commits into one if I already started rebase?

I am trying to merge 2 commits into 1, so I followed “squashing commits with rebase” from git ready. I ran git rebase --interactive HEAD~2 In the resulting editor, I change pick to squash and then save-quit, but the rebase fails with the…
michael
  • 106,540
  • 116
  • 246
  • 346