in-place

In-place edits with sed on OS X

て烟熏妆下的殇ゞ 提交于 2019-11-26 05:53:04
问题 I\'d like edit a file with sed on OS X. I\'m using the following command: sed \'s/oldword/newword/\' file.txt The output is sent to the terminal. file.txt is not modified. The changes are saved to file2.txt with this command: sed \'s/oldword/newword/\' file1.txt > file2.txt However I don\'t want another file. I just want to edit file1.txt . How can I do this? I\'ve tried the -i flag. This results in the following error: sed: 1: \"file1.txt\": invalid command code f 回答1: You can use the -i

Python Pandas - Understanding inplace=True

我怕爱的太早我们不能终老 提交于 2019-11-26 02:33:57
问题 In the pandas library many times there is an option to change the object inplace such as with the following statement... df.dropna(axis=\'index\', how=\'all\', inplace=True) I am curious what is being returned as well as how the object is handled when inplace=True is passed vs. when inplace=False . Are all operations modifying self when inplace=True ? And when inplace=False is a new object created immediately such as new_df = self and then new_df is returned? 回答1: When inplace=True is passed,

Pandas: peculiar performance drop for inplace rename after dropna

喜夏-厌秋 提交于 2019-11-26 02:09:33
问题 I have reported this as an issue on pandas issues. In the meanwhile I post this here hoping to save others time, in case they encounter similar issues. Upon profiling a process which needed to be optimized I found that renaming columns NOT inplace improves performance (execution time) by x120. Profiling indicates this is related to garbage collection (see below). Furthermore, the expected performance is recovered by avoiding the dropna method. The following short example demonstrates a factor

What is the difference between `sorted(list)` vs `list.sort()`?

大兔子大兔子 提交于 2019-11-25 23:39:25
问题 list.sort() sorts the list and save the sorted list, while sorted(list) returns a sorted copy of the list, without changing the original list. But when to use which? And which is faster? And how much faster? Can a list\'s original positions be retrieved after list.sort() ? 回答1: sorted() returns a new sorted list, leaving the original list unaffected. list.sort() sorts the list in-place , mutating the list indices, and returns None (like all in-place operations). sorted() works on any iterable

How to sort in-place using the merge sort algorithm?

混江龙づ霸主 提交于 2019-11-25 22:59:46
问题 I know the question is not too specific. All I want is someone to tell me how to convert a normal merge sort into an in-place merge sort (or a merge sort with constant extra space overhead). All I can find (on the net) is pages saying \"it is too complex\" or \"out of scope of this text\". The only known ways to merge in-place (without any extra space) are too complex to be reduced to practical program. (taken from here) Even if it is too complex, what is the basic concept of how to make the

Delete lines in a text file that contain a specific string

橙三吉。 提交于 2019-11-25 22:06:41
问题 How would I use sed to delete all lines in a text file that contain a specific string? 回答1: To remove the line and print the output to standard out: sed '/pattern to match/d' ./infile To directly modify the file – does not work with BSD sed: sed -i '/pattern to match/d' ./infile Same, but for BSD sed (Mac OS X and FreeBSD) – does not work with GNU sed: sed -i '' '/pattern to match/d' ./infile To directly modify the file (and create a backup) – works with BSD and GNU sed: sed -i.bak '/pattern