[Tutor] help with Pandas
All, I have a dataframe with the column 'loanage' and a function to transform loanage, which will be part of a pipline, I am trying to apply the function to the data frame as follows: df['loanage'].apply(myfunction(x = 2, y = 10, z = 10, df['loanage]), axis = 0) I get value error: The truth in the series is ambigous. However, if I write a for loop indexing into the dataframe the function works. I am of the understanding based on the docs and online research I should be able to do the above. I cannot figure out what I am doing wrong and have tried every possible combination I have seen in the docs and online. Any help is appreciated. Glenn ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Calling class from another class
Dear all, I have created 2 classes in 2 separate files.File 1 named atcore_py.pyx with class andorCameraSDK3, and file 2 with name AndorCameraGUI making use of TKinter. I was able to import andorCameraSDK3 into AndorCameraGUI, but I was not able to do the other way around, as I need to call the function Plot() in file 2 inside function acquireimage() in file 1. When I define self.master = master in file 1 and pass this from file 2 as self.camera = andorCameraSDK3(self) , I get an error saying : > Exception in Tkinter callback > Traceback (most recent call last): > File "/home/ravindra/anaconda2/lib/python2.7/lib-tk/Tkinter.py", line 1541, > in __call__ > return self.func(*args) > File "/home/ravindra/PycharmProjects/LiveMode/GUI.py", line 278, in > getCameraStringGU > self.camera = AndorCameraSDK(self) > File "atcore_py.pyx", line 77, in AndorCameraDriver. > andorCameraSDK3.__cinit__ > self.master = master > AttributeError: 'AndorCameraDriver.andorCameraSDK3' object has no attribute > 'master' > Process finished with exit code 0 > > I'm attaching both the files along with this email. It would be great if someone could help me out here. Thanks in advance -- Regards, Aishwarya Selvaraj ᐧ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] os.walk() with multiple paths
Hello Tutor, I'm stuck and i really need help. Google and I can't find answer for my problem. I've wrote app searching through directories database files. It works fine, but only for one path. And I need to use more than one path. This is my code: import os files = [] def find_db(paths): for path in paths.split(): for root, dirs, filenames in os.walk(path): for name in filenames: if name.endswith((".db", ".sqlite", ".sqlite3")): files.append(name + ', ' + os.path.join(root, name)) return sorted(set(files)) With one path given works great: >>> find_db("/dbbs") ['april.db, /dbbs/analysis/april.db', 'important.sqlite, /dbbs/temp/important.sqlite', 'march.db, /dbbs/analysis/march.db', 'weelky.sqlite3, /dbbs/analysis/queue/weelky.sqlite3'] But with more paths gives files only for last path given: >>> find_db("/home/user/Desktop, /dbbs") ['april.db, /dbbs/analysis/april.db', 'important.sqlite, /dbbs/temp/important.sqlite', 'march.db, /dbbs/analysis/march.db', 'weelky.sqlite3, /dbbs/analysis/queue/weelky.sqlite3'] I was trying to debug this code and I think problem is somewhere here: for path in paths.split(): for root, dirs, filenames in os.walk(path): Can You guide me where i've made mistake? os.walk() accepts one path to look, so was searching something like chain from itertools, or argparse. But none of them works. I couldn't find anything suits my needs. Is there some way do what i need without import anything else than os module? If not what I should search for? Best Regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Calling class from another class
On 22/05/18 11:16, aishwarya selvaraj wrote: > I'm attaching both the files along with this email. It would be great if > someone could help me out here. Thanks in advance I don't see the attachments, even though they may just be text the server probably sees them as potentially executable and strips them out for security reasons. Please repost with the files included rather than attached (or if a lot of code link to a pastebin page) In general you should not need to have a two way import, it suggests a problem with the design. Are you sure you need to import both ways? Can't you simply pass an instance across the interface in one of the directions? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help with Pandas
On 22/05/18 18:13, Glenn Schultz wrote: Cavbeat: I'm no dataframe expert so I'm going on general principles here... > I am trying to apply the function to the data frame as follows: > > df['loanage'].apply(myfunction(x = 2, y = 10, z = 10, df['loanage]), axis = 0) This looks wrong on several counts: 1) apply() usually takes a function object as the first argument not the return value of a function call as here. 2) When calling a function using keyword arguments you re not allowe to have non-keyword arguments following the keyword ones, so the df[...] bit should be an error 3) The df['loanage] does not have a closing quote. > I get value error: The truth in the series is ambigous. I'm not sure if any of the above would result in a ValueError but its possible. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.walk() with multiple paths
On 22/05/18 20:06, Pi wrote: > works fine, but only for one path. And I need to use more than one path. > With one path given works great: > > >>> find_db("/dbbs") > ['april.db, /dbbs/analysis/april.db', 'important.sqlite, > /dbbs/temp/important.sqlite', 'march.db, /dbbs/analysis/march.db', > 'weelky.sqlite3, /dbbs/analysis/queue/weelky.sqlite3'] > > > But with more paths gives files only for last path given: > > >>> find_db("/home/user/Desktop, /dbbs") Note that split() will split based on whitespace so the comma will be included in the first path. That probably renders it invalid and so you don't get any results. Either split by , or use strip() to remove it. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor