Select library column
I have a dataset in which one of the columns contains a library of different 'subcolumns'. For data preparation purposes, I want to extract certain parts of that column and store it into a new column. The data looks like this:
I'm looking to get a new, third, column that contains a header that says 'animal' and contains rows that say 'dog' and 'cat'. Like this:
I usually work with r, and the dplyr library seems the right solution, but no success so far. I'm also familiar with python by the way. Anyone that can be of help?
Thanks in advance!
See also questions close to this topic

How to plot an affinity cluster using scikit
I am clustering some names using scikit's AffinityPropogation and I want to plot/visualize the clusters. My input data has precomputed proximity and this is what it looks like:
#sample input data joe,mike,ali,andrew,sean .2,.221,.5,.5,.7 .82,0,.1,.72,.0 .7,.88,.7,.2,1 0,0,.4,.8,.9 .3,.03,.07,.003,.2
And here is the simple code i have in place for clustering:
import numpy as np import pandas as pd import sklearn.cluster import matplotlib.pyplot as plt from sklearn import metrics data = pd.read_csv('/pydata/nametokenmatrix.txt') M = data.as_matrix() af = sklearn.cluster.AffinityPropagation(affinity="precomputed", damping=0.5) af.fit(M) cluster_centers_indices = af.cluster_centers_indices_ labels = af.labels_
On running this code, i do generate some clusters but I'm unsure how to plot this so that I can visualize them. Since I'm kicking the tires with clusterization, I want to compare different algorithms by plotting them. Something like here.
Thanks

Python Horse Racce
I am doing a lab for a class and was wondering if any of you can guide me on part D and E. It would be greatly appreciated. I know I am a programming noob but any help would be very helpful. THank you.
so part D and E are:
d) Modify the program b) above to accomodate more than one horse. The user should input the number of horses. Each second, generate a different random integer for each horse to indicate its progrerss during that second. The race ends when one (or more) of the horses cross the finish line. If 2 or more horses cross during the same second, the winner is the one that ends up farthest beyond the finish line.
e) Modify the program further to allow the user to enter the horses names. Continue entering names until the name XXX is entered. Do not enter the number of horses, rather count the number of names entered.
As the race is run, at each 10 seconds, the program should announce the position of each horse by name. When the race concludes, announce the name of the winner.
Here is my program
##Part D number_of_ = int(input("How many horses are in the race: ")) distance = [] for i in range(number_of_): distance.append(0) finishline = True print(distance) while finishline: for p in range(len(distance)): distance[p] = horse(distance[p]) if max(distance) <= 10560: finishline = True else: finishline = False print(distance) print("The winner is" , max(distance)) #part E name_of_horses = [] distance_of_horses = [] STOP = XXX ##for i in range(horsey): ## distance_of_horses.append(0) ## name_of_horses.append(input("Name for horse: ")) ##print(name_of_horses) names = input("Enter a name for each horse: ") while names != STOP: name_of_horses.append(names) print(name_of_horses) finish = True count = 0 time = 0 while finish: while count < 10: for o in range(len(distance_of_horses)): distance_of_horses[o] = horse(distance_of_horses[o]) if max(distance_of_horses) <= 10560: finish = True else: finish = True print(distance_of_horses) print("The winner is", max(distance_of_horses))

How does `mock.patch` work for module members?
I am wondering how the following works under the hood, since I would like to achieve this effect in production code (to work around a bad 3rd party package) but cannot find any examples outside of unit tests.
 Is there a minimal example that achieves the same effect without using the
mock
package?  Are there any gotchas to using
mock.patch
to achieve this?  What is the canonical way to achieve this?
`
# bad_module.py import logging class Example: def example(): logging.debug('example spam') # script.py import mock import logging mock.patch('bad_module.logging', logging.getLogger('bad_module')).start() import bad_module logging.basicConfig(level=logging.DEBUG) bad_module.Example().example() # Output DEBUG:bad_module:example spam
I would like to use bad_module.Example without it spamming the root logger  ideally by patching
bad_module.logging
to instead refer tologging.getLogger('bad_module')
.  Is there a minimal example that achieves the same effect without using the

What criteria does the leaps and regsubsets function use in order to select the best variables for the regression? (R language)
i was just wondering what criteria is used by the leaps package and the regsubsets function in order to find the best combination of regressors for a linear regression in the exhaustive search method.
Does the algorithm try to maximize the value of R², minimize the standard error, maximize the Fstatistic, etc?
I just wasn't able to find what criteria are being used when I was reading the package documentation.
Sorry for any inconvenience in this question.

R: Installing, Loading Packages & Verifying these actions. Path, Lib, Dependencies, etc
This is one of the more comprehensive threads and discussions on these topics I have located to date.
How to find out which package version is loaded in R?
Nonetheless, I am finding this has not provided me with sufficient information to ensure I have installed and loaded the two packages I must have before I can begin to expect R to function properly. These packages are: Rserve and MASS.
It seems answers to these topics can be application dependent or, perhaps purpose driven is a better phrase to use. Unfortunately, the R documentation will confuse you so, I thought it best to solicit the input of more experienced users.
I am working on a personal laptop with R 3.5.1 and Win7 Pro. It is clear from the r documentation that Windows is not the best or preferred environment for R.
despite a lot of work something remains missing and I have been unable to identify what it is.

subsetting data based with the condition of the current and previous entity in r
I have data with the
status
column. I want to subset my data to the condition of'f'
status, and previous condition of'f'
status. to simplify:df id status time 1 n 1 1 n 2 1 f 3 1 n 4 2 f 1 2 n 2 3 n 1 3 n 2 3 f 3 3 f 4
my result should be:
id status time 1 n 2 1 f 3 2 f 1 3 n 2 3 f 3 3 f 4
How can I do this in R?

Big Omega notation on 3way merge sort
I've learnt that the time complexity of 3way merge sort(dividing list into 3 sublists) is Nlog3N. this algorithm can be expressed with O notation. But I wonder if the algorithm cannot be expressed with big Omega notation? I'm really curious about it...

Damped sinusoidal form FFT of signal
I'm doing an assignment for the course Signal analysis where I have to analyse a signal. I've tried quite some things now but it's still bothering me that the FFT is looking weird, and not looks like the 'normal look' FFT's we learned in class.
FFT (absolute values of complex values): FFT abs values  FFT abs values zoomed in
FFT (no absolute values): FFT zoomed in
The FFT seen in the image above is zoomed in on the frequency range 030Hz. The rest of the frequency range does not show a lot of (high) peaks, which probably are caused by noise.
The signal is created during a method of welding, using an oscilloscope with a sampling frequency of 1000Hz. I've filtered the signal to remove noise, and after that the signal is converted to the frequency spectrum using the fft function of MATLAB.
Signal before and after filtering: Original signal and filtered signal
My general question is, can the shown FFT be valid or did I make a mistake? I estimated the ground frequency to be around 5.5Hz, can I say this when I take one period of the big sinusoidal wave? I also noticed there are about 64 little sinusoidal waves inside one (ground??) period, is this an high harmonic wave form?.
If my theory is right, what causes the fft to be a damped sinusoidal form?
The code I use is basically the following. I leave the part of the noise filtering out because I don't think it's necessary for this question. The dataset is an matrix of 40100 rows.
fs = 1000; cleanSignaal = data(:,4); fftSignal = fft(cleanSignaal)/lenght(cleanSignaal); f = fs/(2*length(fftSignal)):fs/length(fftSignal):fs; plot(f,abs(fftSignal)); xlim([0 fs(m)/2]); title('Fast Fourier Transform') xlabel('Frequentie (Hz)') ylabel('Magnitude')
Thanks!