scalar

Using conditional statement to subtract scalar from pandas df column gives ValueError: The truth value of a Series is ambiguous

醉酒当歌 提交于 2019-12-12 20:09:35
问题 I'm trying to execute: if df_trades.loc[:, 'CASH'] != 0: df_trades.loc[:, 'CASH'] -= commission and then I get the error. df_trades.loc[:, 'CASH'] is a column of floats. I want to subtract the scalar commission from each entry in that column. For example, df_trades.loc[:, 'CASH'] prints out 2011-01-10 -2557.0000 2011-01-11 0.0000 2011-01-12 0.0000 2011-01-13 -2581.0000 If commission is 1 , I want the result: 2011-01-10 -2558.0000 2011-01-11 0.0000 2011-01-12 0.0000 2011-01-13 -2582.0000 回答1:

Topicalising a variable using “for” is apparently bad. Why?

无人久伴 提交于 2019-12-12 10:12:57
问题 So I answered a question on SO and got a lot of flack for it. I have been using Perl for many years and use this topicalising quite a lot. So let's start with some code. I am doing search and replace in these examples. The idea is to search for one and three from two strings and replace them. $values = 'one two three four five'; $value2 = 'one 2 three four 5'; $values =~ s/one//g; $values =~ s/three//g; $values2 =~ s/one//g; $values2 =~ s/three//g; This code is simple and everyone accepts it.

Perl: Variable is printed as SCALAR(0x7faf2b804240)

落爺英雄遲暮 提交于 2019-12-12 02:29:17
问题 I have a variable that performs well in one section of my code, but not in another. I will attempt to truncate my very long code to give you an idea of what is going on. I will name the variable in question simply "$QuestionableVariable". #!/usr/bin/perl use warnings; use strict; my $QuestionableVariable = LongSubroutine("file.txt"); my $WindowSize = 16; my $StepSize = 1; my %hash = (); for ( my $windowStart = 0; $windowStart <= 140; $windowStart += $StepSize ) { my $Variable_1 = substr($

TSQL XML FUNCTION

醉酒当歌 提交于 2019-12-11 05:07:13
问题 I need help with the following, as my knowledge of XML within SQL is non existent. Below is the table scripts to generate the table and data. In the XML there is a XML Element with a name attribute of "RequiredField", i need to create a TSQL function to return the value contained in the value attribute. Please can anyone assist. CREATE TABLE [MyTable] ( [UniqueID] INT PRIMARY KEY IDENTITY(1,1) NOT NULL, [Description] VARCHAR(50) NOT NULL, [MetaData] XML NOT NULL ) INSERT INTO [MyTable] (

Must declare the scalar variable '@connection' error

依然范特西╮ 提交于 2019-12-11 04:23:26
问题 Below is the code for which am getting must declare scalar variable @connection error. I don't know where I am going wrong. Please guide protected void LinkButton1_Click(object sender, EventArgs e) { string connection = Drpconn.SelectedItem.Text; using (OdbcConnection con = new OdbcConnection("DSN=Sqltesting;UID=user1;PWD=test@123;Integrated Security=no;")) { using (OdbcCommand cmd = new OdbcCommand("INSERT INTO TblConfigure(Connection,Server,DbName,UserID,Password,Connection_Name,Port

Using a scalar as a condition in perl

 ̄綄美尐妖づ 提交于 2019-12-10 14:39:19
问题 First timer...so let me know if there is anything that I have not paid attention to whilst posing a question. The question is how to use a scalar as a condition, as the code below does not work. my @parameter=('hub'); my %condition; $condition{'hub'}{'1'}='$degree>=5'; foreach (@parameter) { if ($condition{$_}{'1'}) {..} } I thought that is because the condition is not interpreted correctly, so I also tried the following, which also did not work. if ("$condition{$parameter}{'1'}") { ..} Would

Detecting element types in a mixed array

本秂侑毒 提交于 2019-12-10 13:09:31
问题 Im working with some code that has a subroutine which includes an array reference as one of the parameters. The elements in this incoming array can be either small arrays or strings. I want to determine what type each element is in order to do something specific (i.e. if the element is an array, drill into it further via indexing, if the element is a string, use the string) I have tried using the ref function to interrogate each array element. It seems to work for elements that are ARRAYs,

What is the difference between the scalar and list contexts in Perl?

老子叫甜甜 提交于 2019-12-09 00:41:00
问题 What is the difference between the scalar and list contexts in Perl and does this have any parallel in other languages such as Java or Javascript? 回答1: Various operators in Perl are context sensitive and produce different results in list and scalar context. For example: my(@array) = (1, 2, 4, 8, 16); my($first) = @array; my(@copy1) = @array; my @copy2 = @array; my $count = @array; print "array: @array\n"; print "first: $first\n"; print "copy1: @copy1\n"; print "copy2: @copy2\n"; print "count:

How should I use Perl's scalar range operator?

情到浓时终转凉″ 提交于 2019-12-08 16:37:53
问题 What is the scalar ".." operator typical usage? Is it only selecting blocks of text? Interesting example by myself: sub get_next { print scalar($$..!$$), "\n"; } get_next for 1 .. 5; # prints numbers from 1 to 5 get_next for 1 .. 5; # prints numbers from 6 to 10 回答1: People hardly seem to know about it based on questions here, but, yes, I'd say typical usage is selecting blocks of text, either with while (<>) { print if /BEGIN/ .. /END/; } or while (<>) { print if 3 .. 5; # prints lines 3

Why does json_decode return a scalar?

扶醉桌前 提交于 2019-12-08 05:22:15
问题 I'm looking for help understanding why json_decode returns a scalar instead of a hash. I'm still learning perl and a description or some reference lit. would be great. So the questions: Why does json_decode return a scalar? (or is it not a scalar) Is there a better way for me to work with the data? Here is my code: use strict; use warnings; use JSON qw(decode_json); use LWP::UserAgent; my $url = "http://api.bf4stats.com/api/playerInfo?plat=xbox&name=Ttylz00&output=json"; my $ua = LWP: