I have a table of profit for different vendors with range of date from OCT 2017 to AUG 2018. The intention is to input one single month and return with the average profit of the three previous months and three following months. (eg. input FEB 2018, return with average of DEC 2017, JAN 2019, FEB 2018, also return with average of FEB, MAR, APR 2018). Tried hlookup but seems did not work for this situation. Please advise.
OCT 2017 NOV 2017 DEC 2017 JAN 2018 FEB 2018 MAR 2018 APR 2018 MAY 2018 JUN 2018 JUL 2018 AUG 2018
Autozone " $4,653 " " $5,584 " " $8,277 " " $7,564 " " $7,321 " " $6,420 " " $7,568 " " $3,546 " " $9,954 " " $8,849 " " $2,325 "
Walmart " $9,838 " " $9,979 " " $2,655 " " $4,795 " " $9,811 " " $8,179 " " $7,896 " " $1,689 " " $7,244 " " $8,969 " " $1,189 "
Target " $8,359 " " $7,683 " " $4,607 " " $4,224 " " $6,221 " " $8,519 " " $5,058 " " $9,184 " " $9,699 " " $1,292 " " $1,080 "
Advanced Auto Parts " $3,674 " " $4,619 " " $3,817 " " $8,741 " " $9,118 " " $5,542 " " $1,578 " " $9,853 " " $8,153 " " $4,710 " " $4,519 "
pre:
=AVERAGE(INDEX($2:$5,0,MATCH(H8,1:1,0)):INDEX($2:$5,0,MATCH(H8,1:1,0)-2))
post:
=AVERAGE(INDEX($2:$5,0,MATCH(H8,1:1,0)):INDEX($2:$5,0,MATCH(H8,1:1,0)+2))
Related
Why the following code returns an exception in the last line?
print(m)
print(b)
print(r)
print(p)
print(se)
print("m: " + m + "\n" + "b: " + b + "\n" + "r: " + r + "\n" + "p " + p + "\n" + "se " + se)
1516.13788561
-5731.63903831
0.858729519032
4.15127287882e-05
250.925294078
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-195-7e2d88a4b5a8> in <module>()
9 print(se)
10
---> 11 print("m: " + m + "\n" + "b: " + b + "\n" + "r: " + r + "\n" + "p " + p + "\n" + "se " + se)
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')
Try casting the variables as strings for the print function.
print("m: " + str(m) + "\n" + "b: " + str(b) + "\n" + "r: " + str(r) + "\n" + "p " + str(p) + "\n" + "se " + str(se))
I'm trying to get Excel VBA to run a list of commands on a Linux server.
I used the following:
Set objShell = CreateObject("WScript.Shell")
cmd = plink & " -ssh -P 22 " & ip & " -l " & username & " -i " & ppk & " -m " & commands_file & " -t "
Set oEx = objShell.Exec(cmd)
where commands_file contains the following:
sudo su - root
/opt/ibm/ccm/collectLogs.sh
When I run it the VB script appears a command line for a while and after it disappears without appearing to run the given instructions on commands_file.
Where is the error?
Please let me know.
I'd like to have a command window opened and see it run the collectLogs without it closing after finished.
I have a project where I build a dotmatrix module and then import it into another program that will print out my initials. I have it done to the point where it will print out my initials, but it won't print the "J" in the
initial = dotmatrix.dotJ("J")
It will just print the "*". I have defined in my module:
def dotJ(char):
"""Creates a capital J in 7 x 7 dots"""
dotJ = " * \n"
dotJ += " * \n"
dotJ += " * \n"
dotJ += " * \n"
dotJ += " * * \n"
dotJ += " * * \n"
dotJ += " *** \n"
return dotJ
where I have the *, I want it to print out whatever is called for in the
initial = dotmatrix.dotJ("J")
A simple way would be to define your dotJ variable with a star and then replace the star with the character:
def dotJ(char):
"""Creates a capital J in 7 x 7 dots"""
dotJ = " * \n"
dotJ += " * \n"
dotJ += " * \n"
dotJ += " * \n"
dotJ += " * * \n"
dotJ += " * * \n"
dotJ += " *** \n"
dotJ = dotJ.replace("*",char)
return dotJ
You could also use a format string. But I suspect this would be less easy to read.
I need to use the function getline to be able to read in the spaces within a string. Currently, I'm reading word by word and any space will input the next word into a different variable. A small extract of the code is as below.
istream & operator >>( istream & input, Unit & C )
{
input >> C.unID >> C.unName >> C.credits >> C.Result >> C.mDay >> C.mMonth >> C.mYear;
return input;
}
ostream & operator <<( ostream & os, const Unit & C )
{
os << " Unit ID: " << C.unID << '\n';
os << " Unit Name: " << C.unName << '\n'
<< " Credits: " << C.credits << '\n'
<< " Result: " << C.Result << " marks" << '\n'
<< " Date: " << C.mDay << " " << C.mMonth << " " << C.mYear << '\n';
return os;
}
Note that I only need getline for unName.
As for the infile, it's in my main.cpp. Code are as below.
ifstream infile( "rinput.txt" );
if( !infile ) return -1;
Student R;
infile >> R;
ofstream ofile( "routput.txt" );
ofile << R
<< "Number of units = " << R.GetCount() << '\n'
<< "Total credits = " << R.GetCredits() << '\n';
The code works fine and all.
If I understand what you are trying to do, the issue is not with your code but with how you organize your input. In your code, if you have Unit::unName contain spaces while all other fields of Unit do not contain spaces, you need to parse your line yourself. The input has to be formatted properly. For example, if you use a delimiter such as ',' in your input file/stdin that does not appear in any valid unName or unId etc., you can use
istream & operator >>( istream & input, Unit & C ) {
input >> C.unID; getline(input,C.unName,','); input >> C.credits; ...
}
instead of,
istream & operator >>( istream & input, Unit & C )
{
input >> C.unID >> C.unName >> C.credits >> C.Result >> C.mDay >> C.mMonth >> C.mYear;
return input;
}
In above, the overloaded form istream& getline (istream& is, string& str, char delim); uses a delimiter such as ',' or '\t' to replace the default \n. You need to use format your input lines with delimiters because otherwise program will not be able to tell if 200 in
1 John Smith 200
should be part of the unName field or the credits field.
So, you can change this to
1, John Smith, 200, ...
and use ',' as the delimiter or change input to
1
John Smith
200
...
and use the default '\n' as the delimiter.
How do I get the range of the data set? Also known as the bounding box for the data. The data is read with the StructuredPointsReader.
Because vtkStructuredPoints (the type of GetOutput() on a vtkStructuredPointsReader) is a subclass of vtkDataSet, you can use the GetBounds(double[6]) function of vtkDataSet. Here is an example:
double bounds[6];
structuredPointsReader->Update();
structuredPointsReader->GetOutput()->GetBounds(bounds);
std::cout << "xmin: " << bounds[0] << " "
<< "xmax: " << bounds[1] << std::endl
<< "ymin: " << bounds[2] << " "
<< "ymax: " << bounds[3] << std::endl
<< "zmin: " << bounds[4] << " "
<< "zmax: " << bounds[5] << std::endl;