So I have multiple different dataframes, all with varying team names under the same column name, 'Team'. I've created a function to run through these all at once, but for some reason it doesn't execute.
def rename(df):
df = df.replace({'Team':
{'NewEngland' : 'Patriots',
'GreenBay' : 'Packers',
'Pittsburgh' : 'Steelers',
'KansasCity' : 'Chiefs',
'Denver' : 'Broncos',
'Seattle' : 'Seahawks',
'Indianapolis' : 'Colts',
'New Orleans' : 'Saints',
'NewOrleans' : 'Saints',
'Dallas' : 'Cowboys',
'Baltimore' : 'Ravens',
'Philadelphia' : 'Eagles',
'Cincinnati' : 'Bengals',
'Carolina' : 'Panthers',
'Tennessee' : 'Titans',
'Arizona' : 'Cardinals',
'Buffalo' : 'Bills',
'SanFrancisco' : '49ers',
'Minnesota' : 'Vikings',
'Washington' : 'Redskins',
'Chicago' : 'Bears',
'Atlanta' : 'Falcons',
'NYGiants' : 'Giants',
'NYJets' : 'Jets',
'Cleveland' : 'Browns',
'Detroit' : 'Lions',
'Miami' : 'Dolphins',
'TampaBay' : 'Buccaneers',
'Jacksonville' : 'Jaguars',
'Houston' : 'Texans',
'HoustonTexans' : 'Texans',
'Oakland' : 'Raiders',
'SanDiego' : 'Chargers',
'St.Louis' : 'Rams',
'LARams' : 'Rams',
'LAChargers' : 'Chargers',
'LasVegas' : 'Raiders',
'LosAngeles' : 'Rams',
'NewYork' : 'Giants',
'KCChiefs' : 'Chiefs',
'Kansas' : 'Chiefs',
'Tampa' : 'Buccaneers'
}})
When I run this code, as seen in the picture, the code does not work - Image
As seen, I ran the function on a bunch of different dataframes, but when I sample one of them, there are no changes to the 'Team' column.
I know my code is correct because when I run the code outside of the function, such as below:
nfl_07 = nfl_07.replace({'Team':
{'NewEngland' : 'Patriots',
'GreenBay' : 'Packers',
'Pittsburgh' : 'Steelers'
etc.
This code works for some reason; my nfl_07 dataframe has the correct Team names... Is there something wrong with my function?
replace does not act in place by default.
In your function you fail to return the renamed DataFrame, when you call the function you fail to assign the output. So nothing happens.
The assignment to df within the function is local. It does not impact the outer scope.
Either modify in place:
def rename(df):
df.replace({'Team':
{'NewEngland' : 'Patriots',
'GreenBay' : 'Packers',
# ...
}}, inplace=True)
rename(nfl_07)
Or return and reassign the output:
def rename(df):
return df.replace({'Team':
{'NewEngland' : 'Patriots',
'GreenBay' : 'Packers',
# ...
}})
nfl_07 = rename(nfl_07)
I have to parse this definition of var agenda (it's Z language):
agenda : \nat \cross \nat \pfun \nat
I want \cross have precedence over \pfun, so if i code:
typeNorm returns [TreeNode node]
: a=typeNorm '\\cross' b=typeNorm
| a=typeNorm \pfun b=typeNorm
it works, produces agenda AST:
\pfun
\cross \nat
\nat \nat
but, if i code:
typeNorm returns [TreeNode node]
: a=typeNorm ('\\cross' b=typeNorm)
| a=typeNorm \pfun b=typeNorm
produces:
\cross
\nat \pfun
\nat \nat
I need to understand why parentesis change precedence
I cannot reproduce this.
For the input a \pfun b \pcross c, both:
typeNorm
: typeNorm '\\pcross' typeNorm
| typeNorm '\\pfun' typeNorm
| ID
;
ID : [a-zA-Z]+;
SPACES : [ \t\r\n]+ -> skip;
and:
typeNorm
: typeNorm ('\\pcross' typeNorm)
| typeNorm '\\pfun' typeNorm
| ID
;
ID : [a-zA-Z]+;
SPACES : [ \t\r\n]+ -> skip;
the following parse tree is produced:
Tested with ANTLR 4.9.2 and 4.9.3.
I have not been able to find a way to sort elements of a TypedPipe in Scalding (when not performing a group operation). Here are the relevant parts of my program (replacing irrelevant parts with ellipses):
case class ReduceOutput(val slug : String, score : Int, json1 : String, json2 : String)
val pipe1 : TypedPipe[(String, ReduceFeatures)] = ...
val pipe2 : TypedPipe[(String, ReduceFeatures)] = ...
pipe1.join(pipe2).map { entry =>
val (slug : String, (features1 : ReduceFeatures, features2 : ReduceFeatures)) = entry
new ReduceOutput(
slug,
computeScore(features1, features2),
features1.json,
features2.json)
}
.write(TypedTsv[ReduceOutput](args("output")))
Is there a way to sort the elements on their score after the map but before the write?
I am new with ANTLR4 and I am trying to visualize the Parse Tree of a text input in a simple form :
grammar Expr;
contract: (I WS SEND WS quantity WS asset WS TO WS beneficiary WS ON WS send_date WS)*;
asset: '$'| 'TND' | 'USD';
quantity:Q;
beneficiary: B;
send_date : day SLASH month SLASH year;
day: D ;
month: M ;
year: Y ;
B : LETTERUP (LETTERLOW+)+ LETTERLOW*;
Q : DIGITO DIGITZ*|DIGITO DIGITZ* POINT DIGITZ*;
D : DIGIT0 DIGITO|(DIGIT1|DIGIT2)DIGITZ|DIGIT3(DIGIT0|DIGIT1);
M : DIGIT0 DIGITO| DIGIT1(DIGIT0|DIGIT1|DIGIT2);
Y : DIGIT2 DIGIT0((DIGIT1(DIGIT7|DIGIT8|DIGIT9))|(DIGIT2 DIGITZ));
I: 'I';
SEND: 'send';
TO:'to' ;
ON: 'on';
LETTER : [a-zA-Z];
LETTERUP : [A-Z];
LETTERLOW : [a-z];
DIGITZ : [0-9];
DIGITO : [1-9];
DIGIT0 : [0];
DIGIT1 : [1];
DIGIT2 : [2];
DIGIT3 : [3];
DIGIT4 : [4];
DIGIT5 : [5];
DIGIT6 : [6];
DIGIT7 : [7];
DIGIT8 : [8];
DIGIT9 : [9];
SLASH:'/';
POINT:'.'|',';
WS : (' ' | '\t' |'\n' |'\r' )+ ;
But it keeps mismatching the send_date as you can see here:
I know it is a seriously complex numerical grammar I did just want some control the 01<= day <= 31 , 01<= month <= 12 and 2017<= year <= 2029 that's all
is there any help? and thanks
The problem happens because your grammar is ambiguous. 07 can match D and 2017 can match Q.
You can fix it like this:
grammar Expr;
contract: (I WS SEND WS quantity WS asset WS TO WS beneficiary WS ON WS send_date WS)*;
asset: '$'| 'TND' | 'USD';
quantity:Q;
beneficiary: B;
send_date : day month year ;
day: D ;
month: M ;
year: Y ;
D : DIGIT0 DIGITO|(DIGIT1|DIGIT2)DIGITZ|DIGIT3(DIGIT0|DIGIT1);
M : SLASH (DIGIT0 DIGITO| DIGIT1(DIGIT0|DIGIT1|DIGIT2));
Y : SLASH (DIGIT2 DIGIT0((DIGIT1(DIGIT7|DIGIT8|DIGIT9))|(DIGIT2 DIGITZ)));
B : LETTERUP (LETTERLOW+)+ LETTERLOW*;
Q : DIGITO DIGITZ*|DIGITO DIGITZ* POINT DIGITZ*;
I: 'I';
SEND: 'send';
TO:'to' ;
ON: 'on';
LETTER : [a-zA-Z];
LETTERUP : [A-Z];
LETTERLOW : [a-z];
DIGITZ : [0-9];
DIGITO : [1-9];
DIGIT0 : [0];
DIGIT1 : [1];
DIGIT2 : [2];
DIGIT3 : [3];
DIGIT4 : [4];
DIGIT5 : [5];
DIGIT6 : [6];
DIGIT7 : [7];
DIGIT8 : [8];
DIGIT9 : [9];
SLASH:'/';
POINT:'.'|',';
WS : (' ' | '\t' |'\n' |'\r' )+ ;
That's a seriously complex numerical grammar. Perhaps you could simplify:
day: NUMBER ;
month: NUMBER ;
year: NUMBER ;
NUMBER : DIGITZ+ ;
DIGITZ : [0-9];
You could enforce semantics like limiting year to [2017...2020] or whatever in your code. Just an idea. Simplifying often helps and then you can enhance it from there, knowing if you make a mistake you can always revert to something that will at least work.
EDIT:
The reason your grammar doesn't work is because the month is being lexed as a day:
[#0,0:0='I',<'I'>,1:0]
[#1,1:1=' ',<WS>,1:1]
[#2,2:5='send',<'send'>,1:2]
[#3,6:6=' ',<WS>,1:6]
[#4,7:9='300',<Q>,1:7]
[#5,10:10=' ',<WS>,1:10]
[#6,11:11='$',<'$'>,1:11]
[#7,12:12=' ',<WS>,1:12]
[#8,13:14='to',<'to'>,1:13]
[#9,15:15=' ',<WS>,1:15]
[#10,16:20='Ahmed',<B>,1:16]
[#11,21:21=' ',<WS>,1:21]
[#12,22:23='on',<'on'>,1:22]
[#13,24:24=' ',<WS>,1:24]
[#14,25:26='03',<D>,1:25]
[#15,27:27='/',<'/'>,1:27]
[#16,28:29='07',<D>,1:28] <-- see, this is being lexed as a D (day)
[#17,30:30='/',<'/'>,1:30]
[#18,31:34='2017',<Q>,1:31] <-- and this is being lexed as a Q (quantity)
[#19,35:36='\r\n',<WS>,1:35]
[#20,37:36='<EOF>',<EOF>,2:0]
line 1:28 mismatched input '05' expecting M
line 1:31 mismatched input '2017' expecting Y
Lexer rules are applied in the order in which they appear, and Day appears before Month. Quantity appears before Year. Hence the improper lexing. This is a scenario, honestly, where I think you need to simplify and just accept numbers. Then in your code, enforce the semantics (make sure year is in range, etc) in your code and provide a helpful error message to the user if values are not in range. Your total effort spend will be less that way.
NEW VERSION
grammar Test2;
contract: (I SEND quantity asset TO beneficiary ON send_date)*;
asset: '$'| 'TND' | 'USD';
send_date : DATE ;
quantity: NUMBER;
beneficiary: B;
DATE : NUMBER SLASH NUMBER SLASH NUMBER ;
B : LETTERUP (LETTERLOW+)+ LETTERLOW*;
I: 'I';
SEND: 'send';
TO:'to' ;
ON: 'on';
LETTER : [a-zA-Z];
LETTERUP : [A-Z];
LETTERLOW : [a-z];
NUMBER: DIGIT+;
DIGIT : [0-9];
SLASH:'/';
POINT:'.'|',';
WS : [ \t\n\r]+ -> skip;
Improvements:
1. Better handling of whitespace much more conventional.
2. Simplified number syntax.
3. It works
[#0,0:0='I',<'I'>,1:0]
[#1,2:5='send',<'send'>,1:2]
[#2,7:9='300',<NUMBER>,1:7]
[#3,11:11='$',<'$'>,1:11]
[#4,13:14='to',<'to'>,1:13]
[#5,16:20='Ahmed',<B>,1:16]
[#6,22:23='on',<'on'>,1:22]
[#7,25:34='03/07/2017',<DATE>,1:25]
[#8,37:36='<EOF>',<EOF>,2:0]
Problem: I simplified away the ability to do decimal numbers for quantity. You can add that back in as you wish.
when I'm trying to open the JMeter script which was copied from another server, im getting below error with a dialog box - Empty Test Plan.
My Machine :
Java Version:1.8.0_72
and apache-jmeter-2.11
Another server from where scripts are copied:
Java version is : 1.8.0_45
and apache-jmeter-2.13
2016/03/14 07:35:47 INFO - jmeter.gui.action.Load: Loading file: C:\XXX Perf Tests\jmeter\apache-jmeter-2.13\tests\stressICXXX.jmx
2016/03/14 07:35:47 INFO - jmeter.services.FileServer: Set new base='C:\XXX Perf Tests\jmeter\apache-jmeter-2.13\tests'
2016/03/14 07:35:49 ERROR - jmeter.save.SaveService: Conversion error com.thoughtworks.xstream.converters.ConversionException: -1 : -1
---- Debugging information ----
message : -1
cause-exception : java.lang.ArrayIndexOutOfBoundsException
cause-message : -1
class : org.apache.jmeter.testelement.property.FloatProperty
required-type : org.apache.jmeter.testelement.property.FloatProperty
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree[5]/hashTree[3]/ThroughputController/FloatProperty/name
line number : 120481
class[1] : org.apache.jmeter.control.ThroughputController
converter-type[1] : org.apache.jmeter.save.converters.TestElementConverter
class[2] : org.apache.jorphan.collections.ListedHashTree
converter-type[2] : org.apache.jmeter.save.converters.HashTreeConverter
------------------------------- : -1 : -1
---- Debugging information ----
message : -1
cause-exception : java.lang.ArrayIndexOutOfBoundsException
cause-message : -1
class : org.apache.jmeter.testelement.property.FloatProperty
required-type : org.apache.jmeter.testelement.property.FloatProperty
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree[5]/hashTree[3]/ThroughputController/FloatProperty/name
line number : 120481
class[1] : org.apache.jmeter.control.ThroughputController
converter-type[1] : org.apache.jmeter.save.converters.TestElementConverter
class[2] : org.apache.jorphan.collections.ListedHashTree
converter-type[2] : org.apache.jmeter.save.converters.HashTreeConverter
-------------------------------
message : -1 : -1
---- Debugging information ----
message : -1
cause-exception : java.lang.ArrayIndexOutOfBoundsException
cause-message : -1
class : org.apache.jmeter.testelement.property.FloatProperty
required-type : org.apache.jmeter.testelement.property.FloatProperty
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree[5]/hashTree[3]/ThroughputController/FloatProperty/name
line number : 120481
class[1] : org.apache.jmeter.control.ThroughputController
converter-type[1] : org.apache.jmeter.save.converters.TestElementConverter
class[2] : org.apache.jorphan.collections.ListedHashTree
converter-type[2] : org.apache.jmeter.save.converters.HashTreeConverter
-------------------------------
cause-exception : com.thoughtworks.xstream.converters.ConversionException
cause-message : -1 : -1
first-jmeter-class : org.apache.jmeter.save.converters.TestElementConverter.unmarshal(TestElementConverter.java:107)
class : org.apache.jmeter.save.ScriptWrapper
required-type : org.apache.jmeter.testelement.property.FloatProperty
converter-type : org.apache.jmeter.save.ScriptWrapperConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree[5]/hashTree[3]/ThroughputController/FloatProperty/name
line number : 120481
version : 2.11 r1554548
-------------------------------
2016/03/14 07:35:49 WARN - jmeter.gui.action.Load: Unexpected error org.apache.jmeter.exceptions.IllegalUserActionException: Empty TestPlan - see log file
at org.apache.jmeter.gui.action.Load.insertLoadedTree(Load.java:174)
at org.apache.jmeter.gui.action.Load.loadProjectFile(Load.java:136)
at org.apache.jmeter.gui.action.Load.loadProjectFile(Load.java:105)
at org.apache.jmeter.gui.action.Load.doAction(Load.java:92)
at org.apache.jmeter.gui.action.ActionRouter.performAction(ActionRouter.java:81)
at org.apache.jmeter.gui.action.ActionRouter.access$000(ActionRouter.java:40)
at org.apache.jmeter.gui.action.ActionRouter$1.run(ActionRouter.java:63)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)