Folium popup gets syntax error message - python-3.x

I'm new to folium. I was able to produce the map I wanted from a dataframe.
df_map = folium.Map(location=[37.750999450684, -97.821998596191], zoom_start=4)
for each in df[0:len(df)].iterrows():
folium.CircleMarker(location=[each[1]["GEO_LAT_0"], each[1]["GEO_LNG_0"]],
radius=5.0, color='#3186cc', fill_color='#3186cc').add_to(df_map)
Map comes out nicely.
Next I wanted to add popups from a third column in data frame, and can't seem to get syntax right. Not clear how I might add these popups from folium documentation. An error message I can't interpret results from this code:
df_map = folium.Map(location=[37.750999450684, -97.821998596191], zoom_start=4)
for each in df[0:len(df)].iterrows():
folium.CircleMarker(location=[each[1]["GEO_LAT_0"], each[1]["GEO_LNG_0"]],
**popup=each[1]["GEO_CITY_0"],**
radius=5.0, color='#3186cc',fill_color='#3186cc').add_to(df_map)
To verify my loop and dataframe were ok, I substituted a
print each[1]["GEO_CITY_0"]
within the for-each loop instead of folium.circlemarker and it worked fine. Something is wrong when I use the popup syntax above.
AttributeError: 'float' object has no attribute 'get_name'
Your help appreciated. Thanks p.s. Full message is:
Traceback (most recent call last):
File "", line 4, in
radius=1, color='#3186cc', fill_color='#3186cc').add_to(df_map)
File "C:\Users\Peter\Anaconda3\lib\site-packages\folium\features.py", line 870, in init
super(CircleMarker, self).init(location=location, popup=popup)
File "C:\Users\Peter\Anaconda3\lib\site-packages\folium\map.py", line 652, in init
self.add_child(popup)
File "C:\Users\Peter\Anaconda3\lib\site-packages\branca\element.py", line 96, in add_child
name = child.get_name()
AttributeError: 'float' object has no attribute 'get_name'

I was under the impression that #pzajonc's syntax of popup=each[1]["GEO_CITY_0"] would work in recent versions (OP's has 0.4.0) of folium.
Here's a github issue that mentions the error and the fix
Regardless, changing it to popup=folium.Popup(each[1]["GEO_CITY_0"]) will resolve the issue.

Related

Hello everyone, I'm currently doing a school project and I'm using python, But I keep running into this error "string argument w/o encoding"

So basically on this block:
if len(args) > 0:
text = u''join(map(bytes, args))
else:
text = sys.stdin.read().strip()
I get an error saying:
Traceback (most recent call last):
File "/home/pi/test.py", line 198, in <module>
text = u''.str.encode()
AttributeError: 'str' object has no attribute 'str'.
If anyone can help me please do. Thank u in advance :)
First, you lost the . between u'' and join in your posted code.
Second, from your posted error log, we can know there is an another syntax error for text = u''.str.encode() in your /home/pi/test.py file. It should be text = u''.encode().

Define fonts for re-use in python fpdf

I´m building PDF document in python with fpdf. Fonts are set in the following way:
pdf.set_font('arial', 'B', 20)
However, this seems a bit unclear if I have to change the font several times (for headings, sub headings, regular text and so on). So I was trying to define fonts upfront in the following form:
heading = ["arial", "B", 20]
sub_heading = ["arial", "B", 15]
And then use the defined fonts later:
pdf.set_font(heading)
Unfortunately this results in the following error:
Traceback (most recent call last):
File "C:\Users\me\PycharmProjects\pythonProject\project\main.py", line 112, in <module>
pdf.set_font(heading)
File "C:\Users\me\PycharmProjects\pythonProject\project\venv\lib\site-packages\fpdf\fpdf.py", line 567, in set_font
family=family.lower()
AttributeError: 'list' object has no attribute 'lower'
So I was wondering, is there any other way to achieve this?
Try to use this:
pdf.set_font(*heading)

how to remove 'int' object is not callable

how to resolve 'int' object is not callable
I am new over here
-68+(((68)**2-4(34)(-510))**0.5)/(2*34)
Traceback (most recent call last):
File "", line 1, in
-68+(((68)**2-4(34)(-510))**0.5)/(2*34)
TypeError: 'int' object is not callable
there is no output only the error message written above. How to resolve this error message?
Python does not support multiplication through parentheses (like (34)(-510) and 4(34)). Change this to (34) * (-510). So, your full line would be:
>>> -68+(((68)**2-4*(34)*(-510))**0.5)/(2*34)
-64.0
When you say 4(34), you're actually telling the interpreter to call the function named 4 with the argument 34. (This is the same syntax as saying a(34), where a is a function.) The error is because 4 is not a function, so you can't call it.
If you don't work in the python interpreter directly, you need to do something with your calcul, like putting it in a variable like this :
a = -68+(((68)**2-4*(34)*(-510))**0.5)/(2*34)
or print it :
print(-68+(((68)**2-4*(34)*(-510))**0.5)/(2*34))
Also you can't do maths with two values into parenthesis, you need to include a '*'.
Finally, doing 4(34) is like you're calling a function named "4", with an argument (34).

PyPDF2, why am I getting an index error? List index out of range

I'm following along in Al Sweigart's book 'Automate the Boring Stuff' and I'm at a loss with an index error I'm getting. I'm working with PyPDF2 tring to open an encrypted PDF document. I know the book is from 2015 so I went to the PyPDF2.PdfFileReader docs to see if I'm missing anything and everything seems to be the same, at least from what I can tell. So I'm not sure what's wrong here.
My Code
import PyPDF2
reader = PyPDF2.PdfFileReader('encrypted.pdf')
reader.isEncrypted # is True
reader.pages[0]
gives:
Traceback (most recent call last):
File "<pyshell#65>", line 1, in <module>
pdfReader.getPage(0)
File "/home/user67/.local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1176, in getPage
self._flatten()
File "/home/user67/.local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1505, in _flatten
catalog = self.trailer["/Root"].getObject()
File "/home/user67/.local/lib/python3.6/site-packages/PyPDF2/generic.py", line 516, in __getitem__
return dict.__getitem__(self, key).getObject()
File "/home/user67/.local/lib/python3.6/site-packages/PyPDF2/generic.py", line 178, in getObject
return self.pdf.getObject(self).getObject()
File "/home/user67/.local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1617, in getObject
raise utils.PdfReadError("file has not been decrypted")
PyPDF2.utils.PdfReadError: file has not been decrypted
pdfReader.decrypt('rosebud')
1
pageObj = reader.getPage(0)
Traceback (most recent call last):
File "<pyshell#67>", line 1, in <module>
pageObj = pdfReader.getPage(0)
File "/home/user67/.local/lib/python3.6/site-packages/PyPDF2/pdf.py",line 1177, in getPage
return self.flattenedPages[pageNumber]
IndexError: list index out of range
Before asking my question, I did some searching on Google and found this link with a "proposed fix". However, I'm to new at this to see what the fix is. I can't make heads or tails out of this.
I figured it out. The issue is caused by running 'pdfReader.getPage(0)' before you decrypt the file in the IDLE shell. If you take that line out, or start over without using that line after getting the error it will work as it should.
Same error I got. I was working on console and before decrypt I used reader.getPage(0).
Don't use getPage(#) / pages[#] before decrypt.
use code like below:
reader = PyPDF2.PdfFileReader("file.pdf")
# reader.pages[0] # do not use this before decrypt
if reader.isEncrypted:
reader.decrypt('')
reader.pages[0]

I don't understand the error traceback gives me

I'm currently trying to understand Pyth. I know Python quite well, but I don't get Pyth sometimes.
My code:
DhNKlNFzrKZaY#Nz;Y;hQ
It's just a basic script for reversing string, and traceback gives me ValueError,
ValueError: malformed node or string: <_ast.Name object at 0x7ff2fde45c18>
Despite my Python knowledge I have no idea what does this error mean. Can you show me where is this error coming from?
I assume you are getting an error like this one here:
Traceback (most recent call last):
File "pyth.py", line 771, in <module>
File "<string>", line 3, in <module>
File "/app/macros.py", line 691, in eval_input
File "/app/.heroku/python/lib/python3.4/ast.py", line 84, in literal_eval
File "/app/.heroku/python/lib/python3.4/ast.py", line 83, in _convert
ValueError: malformed node or string: <_ast.Name object at 0x7fac26eb2b70>
First off, you use z and Q inconsistently. With your current code, input should have been taken like this instead:
"abcd"
abcd
When Q is used in a Pyth program, z implicitly jumps to the next line of input, it just skips whatever has been inputted before using Q. Instead, just use:
DhNKlNFzrKZaY#Nz;Y;hz
And the errors should go away.
I am not sure why you would want to perform string reversal that way, though. I use _z if the input is not quoted and _ alone otherwise, since Q is implicit at the end of any Pyth program.

Resources