我有一个目录,其中包含以下文件:
apple1.json.gz
apple2.json.gz
banana1.json.gz
melon1.json.gz
melon2.json.gz
Run Code Online (Sandbox Code Playgroud)
我希望能够找到所有的apple,banana和melon文件类型.
从这个SO答案我知道我可以通过文件类型找到:
import glob, os
os.chdir("/mydir")
for file in glob.glob("*.json.gz"):
print(file)
Run Code Online (Sandbox Code Playgroud)
但是,就我而言,我无法通过文件名或文件类型进行匹配.而是一个部分文件名匹配(所有apple的等等)
在这个SO问题中,提出了这个解决方案:
[in] for file in glob.glob('/path/apple*.json.gz'):
print file
Run Code Online (Sandbox Code Playgroud)
但是,这会返回零
[out]
0
Run Code Online (Sandbox Code Playgroud) 我希望在scala中找到当前的用户名.
在命令行上我可以这样做:
whoami
Run Code Online (Sandbox Code Playgroud)
在python中,我可以这样做:
import getpass
user_name = getpass.getuser()
Run Code Online (Sandbox Code Playgroud)
如何在Scala中找到用户名?
我有一个包含3列的csv,count_id,AMV和time.
我正在使用熊猫并将其作为数据框阅读.
results= pd.read_csv('./output.csv')
Run Code Online (Sandbox Code Playgroud)
首先,我首先为count_id排序数据帧,然后为AMV排序.
results_sorted = results.sort_index(by=['count_id','AMV'], ascending=[True, True])
Run Code Online (Sandbox Code Playgroud)
这给了
count_id AMV Hour
0 16012E 4004 14
1 16012E 4026 12
2 16012E 4099 15
3 16012E 4167 11
4 16012E 4239 10
5 16012E 4324 13
6 16012E 4941 16
7 16012E 5088 17
8 16012E 5283 9
9 16012E 5620 8
10 16012E 5946 18
11 16012E 6146 7
12 16012W 3622 10
13 16012W 3904 12
14 16012W 3979 11
15 16012W 4076 9
16 16012W …Run Code Online (Sandbox Code Playgroud) 我有一系列与google驱动器文件夹中的协作者团队共享的文档.
是否可以查看有关访问文档的时间和人员的统计信息?
具体来说,我对Google Docs文档感兴趣,但我相信这也应该适用于Sheets和Slides.
我知道显示编辑和评论历史记录的活动Feed.
我有一个数据框df:
id volume saturation time_delay_normalised speed BPR_free_speed BPR_speed Volume time_normalised
27WESTBOUND 580 0.351515152 57 6.54248366 17.88 15.91366177 580 1.59375
27WESTBOUND 588 0.356363636 100 5.107142857 17.88 15.86519847 588 2.041666667
27WESTBOUND 475 0.287878788 64 6.25625 17.88 16.51161331 475 0.666666667
27EASTBOUND 401 0.243030303 59 6.458064516 17.88 16.88283672 401 1.0914583333
27EASTBOUND 438 0.265454545 46 7.049295775 17.88 16.70300418 438 1.479166667
27EASTBOUND 467 0.283030303 58 6.5 17.88 16.55392848 467 0.9604166667
Run Code Online (Sandbox Code Playgroud)
我希望创建一个新的列,free_capacity并将其设置为最大值Volume,每ID当time_normalised大于或等于小于1.1
不考虑time_normalized条件,我可以这样做:
df['free_capacity'] = df.groupby('id')["Volume"].transform('max')
Run Code Online (Sandbox Code Playgroud)
如何添加when time_normalised <= …
我正在mailutils通过dockerfile图像安装ubuntu。
我通过以下方式执行此操作:
RUN apt-get install -y mailutils
然而,在这一行我得到以下信息:
Please select the mail server configuration type that best meets your needs.
No configuration:
Should be chosen to leave the current configuration unchanged.
Internet site:
Mail is sent and received directly using SMTP.
Internet with smarthost:
Mail is received directly using SMTP or by running a utility such
as fetchmail. Outgoing mail is sent using a smarthost.
Satellite system:
All mail is sent to another machine, …Run Code Online (Sandbox Code Playgroud) 我正在从和类型的gz压缩json文件中创建图形。edgevertices
我已将文件放在此处的保管箱文件夹中
我加载并映射这些json记录以创建所需的vertices和edge类型,graphx如下所示:
val vertices_raw = sqlContext.read.json("path/vertices.json.gz")
val vertices = vertices_raw.rdd.map(row=> ((row.getAs[String]("toid").stripPrefix("osgb").toLong),row.getAs[Long]("index")))
val verticesRDD: RDD[(VertexId, Long)] = vertices
val edges_raw = sqlContext.read.json("path/edges.json.gz")
val edgesRDD = edges_raw.rdd.map(row=>(Edge(row.getAs[String]("positiveNode").stripPrefix("osgb").toLong, row.getAs[String]("negativeNode").stripPrefix("osgb").toLong, row.getAs[Double]("length"))))
val my_graph: Graph[(Long),Double] = Graph.apply(verticesRDD, edgesRDD).partitionBy(PartitionStrategy.RandomVertexCut)
Run Code Online (Sandbox Code Playgroud)
然后,我使用dijkstra发现的这种实现来计算两个顶点之间的最短路径:
def dijkstra[VD](g: Graph[VD, Double], origin: VertexId) = {
var g2 = g.mapVertices(
(vid, vd) => (false, if (vid == origin) 0 else Double.MaxValue, List[VertexId]())
)
for (i …Run Code Online (Sandbox Code Playgroud) 我正在使用.groupby和.size方法从之前的数据框架创建一个新的pandas数据框.
[in] results = df.groupby(["X", "Y", "Z", "F"]).size()
[out]
9 27/02/2016 1 N 326
9 27/02/2016 1 S 332
9 27/02/2016 2 N 280
9 27/02/2016 2 S 353
9 27/02/2016 3 N 177
Run Code Online (Sandbox Code Playgroud)
这表现得如预期,但结果是没有列标题的数据帧.
此SO问题表明以下内容将列名添加到生成的数据帧中
[in] results.columns = ["X","Y","Z","F","Count"]
Run Code Online (Sandbox Code Playgroud)
但是,这似乎没有任何影响.
[out]
9 27/02/2016 1 N 326
9 27/02/2016 1 S 332
9 27/02/2016 2 N 280
9 27/02/2016 2 S 353
9 27/02/2016 3 N 177
Run Code Online (Sandbox Code Playgroud) 我datetime64[ns]在pandas数据帧中有一个格式对象.
我可以使用此列来计算小时:
df['hour'] = df['datetime'].dt.hour
Run Code Online (Sandbox Code Playgroud)
这将返回一个整数.例如:
datetime hour
19-10-2015 2015-10-19 01:00:00 1
Run Code Online (Sandbox Code Playgroud)
hour以01:00:00时间格式输出列的最简单方法是什么?
我有一系列 GeoJSON 对象,我希望以编程方式在地图上渲染它们。
我可以使用http://geojson.io并上传我的 GeoJSON,但如何以编程方式执行此操作并导出 PNG 或其他图像文件?
https://github.com/mapbox/geojson.io看起来很棒,但它公开发布到 geojson.io 网站。
python ×6
pandas ×4
apache-spark ×1
docker ×1
dockerfile ×1
geojson ×1
glob ×1
google-docs ×1
json ×1
lambda ×1
linux ×1
scala ×1
smtp ×1
spark-graphx ×1
ubuntu ×1