我有一张地图:
map_osm = folium.Map(location=[51.366975, 0.039039],zoom_start=12)
map_osm
Run Code Online (Sandbox Code Playgroud)
我希望能够添加一个矩形标记,我可以根据一些统计数据为其着色。我找到了一个polygon_marker
(http://bl.ocks.org/wrobstory/5609786'Map' object has no attribute 'polygon_marker'
),但当我尝试时收到错误:
map_osm.polygon_marker(location=[45.5132, -122.6708], popup='Hawthorne Bridge',
fill_color='#45647d', num_sides=4, radius=10)
Run Code Online (Sandbox Code Playgroud)
在最终产品中,我希望对许多矩形进行颜色编码。
有什么建议
我有一个 6k 列宽的数据框,格式为:
import pandas as pd
df = pd.DataFrame([('jan 1 2000','a','b','c',1,2,3,'aa','bb','cc'), ('jan 2 2000','d', 'e', 'f', 4, 5, 6, 'dd', 'ee', 'ff')],
columns=['date','a_1', 'a_2', 'a_3','b_1', 'b_2', 'b_3','c_1', 'c_2', 'c_3'])
df
date a_1 a_2 a_3 b_1 b_2 b_3 c_1 c_2 c_3
0 jan 1 2000 a b c 1 2 3 aa bb cc
1 jan 2 2000 d e f 4 5 6 dd ee ff
Run Code Online (Sandbox Code Playgroud)
我想:
我看过: Pandas 按名称将几组列融化成多个目标列和Pandas:多列合并成一列,但无法形成正确的解决方案。
任何建议表示赞赏
我有:
pd.DataFrame({'col':['one','fish','two','fish','left','foot','right','foot']})
col
0 one
1 fish
2 two
3 fish
4 left
5 foot
6 right
7 foot
Run Code Online (Sandbox Code Playgroud)
我想连接每 n 行(这里是每 4 行)并形成一个新的数据框:
pd.DataFrame({'col':['one fish two fish','left foot right foot']})
col
0 one fish two fish
1 left foot right foot
Run Code Online (Sandbox Code Playgroud)
我正在使用pyhton和pandas
我有一个字符串:
a="<gml:posList srsDimension=\"2\" count=\"5\">7 -5.067 -3 56.7 -3.3 58.3 -5.65 57 -8.33</gml:posList>"
Run Code Online (Sandbox Code Playgroud)
并希望gsub <和>之间的所有内容,到目前为止现在都有用.我想只剩下数字(即7 -5 -3 56 -3 58 ...),我可以在其中处理每个偶数/奇数元素.
我尝试删除两个括号之间的所有文本无济于事
> gsub('<^|*>','',a[[1]],perl=TRUE)
Error in gsub("<^|*>", "", a[[1]], perl = TRUE) :
invalid regular expression '<^|*>'
In addition: Warning message:
In gsub("<^|*>", "", a[[1]], perl = TRUE) : PCRE pattern compilation error
'nothing to repeat'
at '*>'
Run Code Online (Sandbox Code Playgroud)
和
gsub('<gml.+>\\d','',a[[1]])
Run Code Online (Sandbox Code Playgroud)
哪些剪切删除了第一个数字
我确信我错过了一些明显的东西,因为'<'不是一个特殊的角色.
这是其他一些尝试(并失败)
> gsub('<.+>','',a[[1]])
[1] ""
> gsub('<.+>.+<.+>','',a[[1]])
[1] ""
> gsub('<gml.+>','',a[[1]])
[1] ""
Run Code Online (Sandbox Code Playgroud) 我有:
df=pd.DataFrame({'a':[1,1,2],'b':[[1,2,3],[2,5],[3]],'c':['f','df','ere']})
df
a b c
0 1 [1, 2, 3] f
1 1 [2, 5] df
2 2 [3] ere
Run Code Online (Sandbox Code Playgroud)
我想连接并在每个元素上创建一个列表:
pd.DataFrame({'a':[1,2],'b':[[1,2,3,2,5],[3]],'c':[['f', 'df'],['ere']]})
a b c
0 1 [1, 2, 3, 2, 5] [f, df]
1 2 [3] [ere]
Run Code Online (Sandbox Code Playgroud)
我试过:
df.groupby('a').agg({'b': 'sum', 'c': lambda x: list(''.join(x))})
a b c
1 [1, 2, 3, 2, 5] [f, d, f]
2 [3] [e, r, e]
Run Code Online (Sandbox Code Playgroud)
但这并不完全正确。
有什么建议吗?
我有600k行,并希望删除开始和尾随空格.我有以下,但它很慢:
Sub Macro1()
'
' Macro1 Macro
'
'
Range("D1").Select
ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
Range("D1").Select
Selection.AutoFill Destination:=Range("D1:D4")
Range("D1:D4").Select
Columns("D:D").Select
Selection.Copy
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("D:D").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("C1").Select
End Sub
Run Code Online (Sandbox Code Playgroud)
有没有办法可以自己应用这个功能.我想避免在空列中运行函数,然后将值复制到原始列.
我尝试了VBA将公式填写到列的最后一行,以及加快公式.我有几个列可以做到这一点,并想知道是否可以只在C列上工作并修剪空格而不需要额外的计算.
谢谢