How to iterate over rows in a DataFrame in Pandas
2022-05-01
Question I have a pandas dataframe, df: c1 c2 0 10 100 1 11 110 2 12 120 How do I iterate over the rows of this dataframe? For every row, I want to access its elements (values in cells) by the name of the columns. For example: for row in df.rows: print(row['c1'], row['c2']) I found a similar question, which suggests using either of these: for date, row in df.T.iteritems(): for row in df.…
Why did my Git repo enter a detached HEAD state?
2022-05-01
Question I ended up with a detached head today, the same problem as described in: git push says everything up-to-date even though I have local changes As far as I know I didn't do anything out of the ordinary, just commits and pushes from my local repo. So how did I end up with a detached HEAD? Answer Any checkout of a commit that is not the name of one of your branches will get you a detached HEAD.…
Git push existing repo to a new and different remote repo server?
2022-04-30
Question Say I have a repository on git.fedorahosted.org and I want to clone this into my account at github to have my own playground aside from the more "official" repo on fedorahosted. What would be the steps to initially copy that over? Within github there is this nice "fork" button, but I can't use this for obvious reasons. And how would I track changes in the fedorahosted repo into the github one?…
How can I Remove .DS_Store files from a Git repository?
2022-04-29
Question How can I remove those annoying Mac OS X .DS_Store files from a Git repository? Answer Remove existing .DS_Store files from the repository: find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch Add this line: .DS_Store to the file .gitignore, which can be found at the top level of your repository (or create the file if it isn't there already). You can do this easily with this command in the top directory:…
How do I edit an existing tag message in Git?
2022-04-29
Question We have several annotated tags in our Git repository. The older tags have bogus messages that we would like to update to be in our new style. % git tag -n1 v1.0 message v1.1 message v1.2 message v2.0 Version 2.0 built on 15 October 2011. In this example, we would like to make v1.x messages look like the v2.0 message. How would we do this? Answer git tag <tag name> <tag name>^{} -f -m "…
Specify an SSH key for git push for a given domain
2022-04-29
Question I have the following use case: I would like to be able to push to git@git.company.com:gitolite-admin using the private key of user gitolite-admin, while I want to push to git@git.company.com:some_repo using 'my own' private key. AFAIK, I can't solve this using ~/.ssh/config, because the user name and server name are identical in both cases. As I mostly use my own private key, I have that defined in ~/.ssh/config for git@git.…
How to clone a specific Git tag
2022-04-28
Question From git-clone(1) Manual Page --branch can also take tags and detaches the HEAD at that commit in the resulting repository. I tried git clone --branch <tag_name> <repo_url> But it does not work. It returns: warning: Remote branch 2.13.0 not found in upstream origin, using HEAD instead How to use this parameter? Answer git clone --depth 1 --branch <tag_name> <repo_url> --depth 1 is optional but if you only need the state at that one revision, you probably want to skip downloading all the history up to that revision.…