Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
116 views
in Technique[技术] by (71.8m points)

python - Create new variable from combined variables

I have created a python script which uses tensorflow with deep sort to detect and track vehicles in a video. Depending on each vehicles position it gets a value to its attributes Each vehicle has the following: Car.Id Car.Origin Car.Destination

Origin and Destination can be any of E, N, S or V (but not the same).

So each vehicle should then have an ID, Origin and Destination as in

 Car.Id = 575
 Car.Origin = E
 Car.Destination = V

Now I append these to a Pandas dataframe and I can export unique combinations as in

 sum((df['orig']=='E') & (df['dest']=='V'))

However, this would mean I need to update 12 different variables in each loop (EE, EV, ES, NV, NS etc etc.)

So, I tried to dynamically create and set values through the loop as in the following code

exec(str(track.origin + track.destination) + "=" + str(sum((df['orig']==track.origin) & (df['dest']==track.destination))))

But still Print(EV) doesn't work. So, I am stuck. Should i put E, V, N, S in some dictionary and loop around it, or do you guys have any other tip or recommendation? I really want these simple variables as EV and SV for different reasons.

question from:https://stackoverflow.com/questions/65923542/create-new-variable-from-combined-variables

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...