Change column type in pandas
2022-07-10
Question I created a DataFrame from a list of lists: table = [ ['a', '1.2', '4.2' ], ['b', '70', '0.03'], ['x', '5', '0' ], ] df = pd.DataFrame(table) How do I convert the columns to specific types? In this case, I want to convert columns 2 and 3 into floats. Is there a way to specify the types while converting the list to DataFrame? Or is it better to create the DataFrame first and then loop through the columns to change the dtype for each column?…
Find when a file was deleted in Git
2022-07-10
Question I have a Git repository with n commits. I have a file that I need, and that used to be in the repository, and that I suddenly look for and think "Oh! Where'd that file go?" Is there a (series of) Git command(s) that will tell me that "file really_needed.txt was deleted at commit n-13"? In other words, without looking at every individual commit, and knowing that my Git repo has every change of every file, can I quickly find the last commit that HAS that file, so I can get it back?…
How to specify the private SSH-key to use when executing shell command on Git?
2022-07-09
Question A rather unusual situation perhaps, but I want to specify a private SSH-key to use when executing a shell (git) command from the local computer. Basically like this: git clone git@github.com:TheUser/TheProject.git -key "/home/christoffer/ssh_keys/theuser" Or even better (in Ruby): with_key("/home/christoffer/ssh_keys/theuser") do sh("git clone git@github.com:TheUser/TheProject.git") end I have seen examples of connecting to a remote server with Net::SSH that uses a specified private key, but this is a local command. Is it possible?…
How to have 'git log' show filenames like 'svn log -v'
2022-07-08
Question SVN's log has a "-v" mode that outputs filenames of files changed in each commit, like so: jes5199$ svn log -v ------------------------------------------------------------------------ r1 | jes5199 | 2007-01-03 14:39:41 -0800 (Wed, 03 Jan 2007) | 1 line Changed paths: A /AUTHORS A /COPYING A /ChangeLog A /EVOLUTION A /INSTALL A /MacOSX Is there a quick way to get a list of changed files in each commit in Git? Answer For full path names of changed files:…
Pull latest changes for all git submodules
2022-07-08
Question We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest version of every dependent submodule. How do I pull the latest changes for all git submodules? Answer If it's the first time you check-out a repo you need to use --init first:…
Should Gemfile.lock be included in .gitignore?
2022-07-05
Question I'm sort of new to bundler and the files it generates. I have a copy of a git repo from GitHub that is being contributed to by many people so I was surprised to find that bundler created a file that didn't exist in the repo and wasn't in the .gitignore list. Since I have forked it, I know adding it to the repo won't break anything for the…
How can I stop .gitignore from appearing in the list of untracked files?
2022-07-03
Question I just did a git init on the root of my new project. Then I created a .gitignore file. Now, when I type git status, .gitignore file appears in the list of untracked files. Why is that? Answer The .gitignore file should be in your repository, so it should indeed be added and committed in, as git status suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.…