concatenation

Concatenate column values in Pandas DataFrame with “NaN” values

浪子不回头ぞ 提交于 2019-12-30 04:18:06
问题 I'm trying to concatenate Pandas DataFrame columns with NaN values. In [96]:df = pd.DataFrame({'col1' : ["1","1","2","2","3","3"], 'col2' : ["p1","p2","p1",np.nan,"p2",np.nan], 'col3' : ["A","B","C","D","E","F"]}) In [97]: df Out[97]: col1 col2 col3 0 1 p1 A 1 1 p2 B 2 2 p1 C 3 2 NaN D 4 3 p2 E 5 3 NaN F In [98]: df['concatenated'] = df['col2'] +','+ df['col3'] In [99]: df Out[99]: col1 col2 col3 concatenated 0 1 p1 A p1,A 1 1 p2 B p2,B 2 2 p1 C p1,C 3 2 NaN D NaN 4 3 p2 E p2,E 5 3 NaN F NaN

Notice : Undefined variable when concatenating

徘徊边缘 提交于 2019-12-29 09:38:13
问题 I have been making a script to display users and make changes to their admin privileges. Here is the code: while ($row= mysql_fetch_assoc($query)) { $uname= $row['username']; $fname= $row['first_name']; $lname= $row['last_name']; $email= $row['email']; $admin= $row['admin']; $insert .= '<tr> <td>' .$uname. '</td> <td>' .$fname. '</td> <td>' .$lname. '</td> <td>' .((isset($email)) ? $email:'No email set.'). '</td> <td>'.(($admin == 'y') ? 'Admin':'User').'</td> <td><input type="checkbox" name=

Notice : Undefined variable when concatenating

风格不统一 提交于 2019-12-29 09:38:06
问题 I have been making a script to display users and make changes to their admin privileges. Here is the code: while ($row= mysql_fetch_assoc($query)) { $uname= $row['username']; $fname= $row['first_name']; $lname= $row['last_name']; $email= $row['email']; $admin= $row['admin']; $insert .= '<tr> <td>' .$uname. '</td> <td>' .$fname. '</td> <td>' .$lname. '</td> <td>' .((isset($email)) ? $email:'No email set.'). '</td> <td>'.(($admin == 'y') ? 'Admin':'User').'</td> <td><input type="checkbox" name=

Excel concatenate

自古美人都是妖i 提交于 2019-12-29 09:24:26
问题 I would like to concatenate data from two cells into one cell. I would also like to only combine those cells that have the same ID. Task ID Name 4355.2 Participant 4355.2 Leader 4462.1 Online 4462.1 Quick 4597.1 Slide 4597.1 One Page 4597.1 One Topic For example, for this, I would like a cell for 4355.2 with "Participant, Leader" as the data in that cell. The same type of data for 4462.1 with "Online and Quick" as the data for that cell. Task ID Name 4355.2 Participant, Leader Is there a way

What is wrong with this MATLAB code?

安稳与你 提交于 2019-12-29 08:54:09
问题 I am trying to do following in MATLAB, global a b c d e f g h l; A=[1 3;3 2]; B=[a 0;0 b]; C=[d 0;e f]; Ctranspose=transpose(C); D=[sqrt(d) 0;0 sqrt(f)]; E=Ctranspose/D; Etranspose=transpose(E); K=A+E; M=E*D*Etranspose; for a=1:10 for b=1:10 if K==M print(a); print(b); print(d); print(e); print(f); end end end I get following errors: a) Error using + Matrix dimensions must agree. Error in trial (line 6) K=A+B b) Error using vertcat CAT arguments dimensions are not consistent. Error in trial

Ruby equivalent of PHP's “.=” (dot equals) operator

两盒软妹~` 提交于 2019-12-29 08:20:56
问题 In PHP we can quickly concatenate strings: $a = "b"; $a .= "c"; which returns "bc" . How would we do this in Ruby? 回答1: irb(main):001:0> a = "ezcezc" => "ezcezc" irb(main):002:0> a << "erer" => "ezcezcerer" or irb(main):003:0> a += "epruneiruv" => "ezcezcererepruneiruv" 回答2: There are essentially two different ways: Concatenation in place with << (known as the "shovel"), this is equivalent to calling concat. Note that, like most operators in Ruby, << is a method call . str = "foo" str << "bar

Why SQL Server Ignores vaules in string concatenation when ORDER BY clause specified

假装没事ソ 提交于 2019-12-29 08:09:08
问题 I have the following table Created Comment 2010/10/10 Text1 2010/11/11 Text2 2010/12/12 Text3 I need gather all comments into the single string SELECT @Comment = COALESCE(@Comment, '') + CHAR(13) + CHAR(10) + CONVERT(NVARCHAR(30), [dbo].[Comment].[Created], 101) + ': ' + ISNULL([Comment].[Text], '') FROM Comment Without ordering it works as expected end return all thee comments. But after running following code where ORDER BY clause is added: SELECT @Comment = COALESCE(@Comment, '') + CHAR(13

Why SQL Server Ignores vaules in string concatenation when ORDER BY clause specified

筅森魡賤 提交于 2019-12-29 08:09:04
问题 I have the following table Created Comment 2010/10/10 Text1 2010/11/11 Text2 2010/12/12 Text3 I need gather all comments into the single string SELECT @Comment = COALESCE(@Comment, '') + CHAR(13) + CHAR(10) + CONVERT(NVARCHAR(30), [dbo].[Comment].[Created], 101) + ': ' + ISNULL([Comment].[Text], '') FROM Comment Without ordering it works as expected end return all thee comments. But after running following code where ORDER BY clause is added: SELECT @Comment = COALESCE(@Comment, '') + CHAR(13

String concatenation in a for loop. Java 9

末鹿安然 提交于 2019-12-29 06:48:09
问题 Please correct me if i'm wrong. In Java 8, for performance reasons, when concatenating several strings by the "+" operator StringBuffer was invoked. And the problem of creating a bunch of intermediate string objects and polluting the string pool was "resolved". What about Java 9? There'a new feature added as Invokedynamic. And a new class that resolves the problem even better, StringConcatFactory. String result = ""; List<String> list = Arrays.asList("a", "b", "c"); for (String n : list) {

List += Tuple vs List = List + Tuple

╄→尐↘猪︶ㄣ 提交于 2019-12-28 06:40:09
问题 Let's say I have these assignments: points = [] point = (1, 2) How come when I do this: points += point It works completely fine, and gives me points = [1, 2]. However, If I do something like: points = points + point It gives me a TypeError: can only concatenate list (not "tuple") to list. Aren't these statements the same thing, though? 回答1: The difference, is that list += is equivalent to list.extend() , which takes any iterable and extends the list, it works as a tuple is an iterable. (And