小编Duc*_*ani的帖子

同一图中的大熊猫数据框的多列的箱形图(seaborn)

我觉得我可能没想到明显的东西.我想在同一个图中输入数据帧每一列的方框图,在x轴上我有列的名称.在seaborn.boxplot()这将是groupby每列的等于.

在熊猫我会做

df = pd.DataFrame(data = np.random.random(size=(4,4)), columns = ['A','B','C','D'])
df.boxplot()
Run Code Online (Sandbox Code Playgroud)

产量

在此输入图像描述

现在我想在seaborn得到同样的东西.但是当我尝试sns.boxplot(df)时,我只得到一个分组的boxplot.如何在seaborn中重现相同的数字?

谢谢

python pandas seaborn

13
推荐指数
2
解决办法
2万
查看次数

绘制 GeoDataFrame 一行的几何图形

我想绘制 geopandas 数据帧的单行中包含的几何图形,但我遇到了问题。这里有一个例子

import geopandas as gpd
import numpy as np
from shapely.geometry import Polygon

p1 = Polygon([(0, 0), (1, 0), (1, 1)])
p2 = Polygon([(2, 0), (3, 0), (3, 1), (2, 1)])
p3 = Polygon([(1, 1), (2, 1), (2, 2), (1, 2)])
index = np.random.random(3)
df = gpd.GeoDataFrame()
df['index'] = index
df['geometry'] = [p1,p2,p3]
df = df.set_geometry('geometry')
Run Code Online (Sandbox Code Playgroud)

现在,如果我使用df.plot()我得到的命令进行绘图

在此处输入图片说明

但如果我尝试只绘制一行, df.loc[:,0].plot()

我收到以下错误

TypeError: Empty 'DataFrame': no numeric data to plot,

而如果我尝试

df.loc[:,'geometry'].plot()

我得到 AttributeError: 'Polygon' object has …

python pandas geopandas

8
推荐指数
1
解决办法
4872
查看次数

Python 和 C++:如何将 pybind11 与 Cmakelists(包括 GSL 库)一起使用

我希望能够将我的 C++ 代码作为 python 包调用。为此,我使用pybind11CMakelists (遵循此示例https://github.com/pybind/cmake_example)。我的问题是我必须在代码编译中包含 GSL 库,并且这些库需要显式链接器 -lgsl

如果我只是编译并运行 C++,而不用 python 包装它,则以下 Cmakelists.txt 文件可以完成这项工作

cmake_minimum_required(VERSION 3.0)

set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

project(myProject)


add_executable(
    myexecutable
    main.cpp
    function1.cpp
)

find_package(GSL REQUIRED)
target_link_libraries(myexecutable GSL::gsl GSL::gslcblas)
Run Code Online (Sandbox Code Playgroud)

但当使用pybind11模板时,我发现不允许,add_executable因此 target_link_libraries不起作用。

我已经尝试过这个

project(myProject)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)   # See below (1)



# Set source directory
set(SOURCE_DIR "project")

# Tell CMake that headers are also in SOURCE_DIR
include_directories(${SOURCE_DIR})
set(SOURCES "${SOURCE_DIR}/functions.cpp")


# Generate Python module
add_subdirectory(lib/pybind11)
pybind11_add_module(namr ${SOURCES} …
Run Code Online (Sandbox Code Playgroud)

c++ python cmake pybind11

8
推荐指数
1
解决办法
9134
查看次数

在Pandas DataFrame列上应用阈值

我有一个看起来像这样的Daframe

In [52]: f
Out[52]:
Date
2015-02-23 12:00:00    0.172517
2015-02-23 13:00:00    0.172414
2015-02-23 14:00:00    0.172516
2015-02-23 15:00:00    0.173261
2015-02-23 16:00:00    0.172921
2015-02-23 17:00:00    0.172371
2015-02-23 18:00:00    0.176374
2015-02-23 19:00:00    0.177480
    ...
Run Code Online (Sandbox Code Playgroud)

并且我想对该系列应用一个阈值,以便值低于它我只是将阈值的值替换为实际值.

我试图definte一个布尔数据帧,如

Bool = f>阈值

但我不知道该怎么做.提前致谢.

python boolean time-series pandas

4
推荐指数
1
解决办法
6928
查看次数

在 Geopandas 中转换 shapefile 的坐标

我是空间分析的新手,但我在任何地方都找不到这个答案。

我有一个 CRS 坐标、纬度和经度的邮政编码列表,以及 OSN 坐标中的伦敦自治市形状文件,我想将它们映射在一起,但这就是发生的情况。这是邮政编码的头部

london_post_codes.head()
Out[81]:
postcode    latitude    longitude
0   WD6 1GS 51.658021   -0.255663
1   WD17 1LA    51.660366   -0.397525
2   WC2N 6LE    51.509413   -0.121676
3   WC2N 6NA    51.508363   -0.124454
4   WC2N 6ND    51.508216   -0.123829
Run Code Online (Sandbox Code Playgroud)

虽然这是在 geopandas 中读取的形状文件

borough = gpd.read_file('London_Borough_Excluding_MHW.shp')
borough.head()
borough.head()

NAME    GSS_CODE    geometry
0   Kingston upon Thames    E09000021   POLYGON ((516401.6 160201.8, 516407.3 160210.5...
1   Croydon E09000008   POLYGON ((535009.2 159504.7, 535005.5 159502, ...
2   Bromley E09000006   POLYGON ((540373.6 157530.4, 540361.2 157551.9...
3   Hounslow    E09000018   POLYGON ((521975.8 178100, …
Run Code Online (Sandbox Code Playgroud)

python location geolocation pandas geopandas

3
推荐指数
1
解决办法
4953
查看次数