我知道如何使用Anaconda的安装软件包conda install
以及如何安装上的包的PyPI这是在描述手册.
但是,如何将包/文件夹永久地包含PYTHONPATH
在Anaconda环境中,以便我可以导入当前正在处理的代码,并且在重新启动后仍然可用?
我目前的做法是使用sys
:
import sys
sys.path.append(r'/path/to/my/package')
Run Code Online (Sandbox Code Playgroud)
这不是很方便.
任何提示?
提前致谢!
我非常喜欢处理和分析大数据集的熊猫.到目前为止,我主要使用matplotlib进行绘图,但现在想要使用pandas自己的绘图功能(基于matplotlib),因为它需要更少的代码,并且在大多数情况下似乎对我来说足够了.特别是在下面的例子中对大数据帧进行了一瞥的子图.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Generate random data
df = pd.DataFrame(np.random.randn(96,12),
columns=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L'])
# Plotting
df.plot(kind='line', subplots=True, grid=True, title="Sample Data (Unit)",
layout=(4, 3), sharex=True, sharey=False, legend=True,
style=['r', 'r', 'r', 'g', 'g', 'g', 'b', 'b', 'b', 'r', 'r', 'r'],
xticks=np.arange(0, len(df), 16))
Run Code Online (Sandbox Code Playgroud)
..我带来了我的问题:
1.)如何将所有图例放在子图中的同一位置(例如居中,外面,顶部)?
2.)我可以以某种方式使用matplotlibs"Tight Layout"(http://matplotlib.org/users/tight_layout_guide.html)作为情节吗?
提前致谢!
我最近使用本教程切换到vim并将其配置为Python编程.之前,我已经确保Vim支持python3使用(VIM --version显示+蟒蛇/ DYN和+ python3/DYN)本文章.
但是当从python-mode执行文件时,仍然会选择python2.7解释器.
如何配置vim(或python-mode)在python3解释器上运行文件?
我的操作系统是Ubuntu 14.04 x64.
提前致谢!
我想知道如何将matplotlibs ="post"传递到pandas图中.
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(36, 3))
df.plot(drawstyle="steps", linewidth=2)
# this doesn't work
df.plot(drawstyle="steps", where='post')
Run Code Online (Sandbox Code Playgroud)
有谁知道如何实现这一点?
提前致谢!
我正在使用新的多页功能,并且想要设计我的多页应用程序的样式,并将带有标题的徽标放在页面导航的顶部/之前。
这是在以下目录结构中Python 3.9
测试的一个小示例:streamlit==1.11.1
/Home.py
/pages/Page_1.py
/pages/Page_2.py
Run Code Online (Sandbox Code Playgroud)
Home.py
:
import streamlit as st
st.sidebar.markdown(
"My Logo (sidebar) should be on top of the Navigation within the sidebar"
)
st.markdown("# Home")
Run Code Online (Sandbox Code Playgroud)
Page_1.py
:
import streamlit as st
st.markdown("Page 1")
Run Code Online (Sandbox Code Playgroud)
Page_2.py
:
import streamlit as st
st.markdown("Page 2")
Run Code Online (Sandbox Code Playgroud)
我可以使用以下命令运行:
$ streamlit run Home.py
Run Code Online (Sandbox Code Playgroud)
有什么办法可以做到这一点吗?欢迎任何提示!
最美好的祝愿,科德
假设我有一个多索引的pandas数据框,看起来像下面这个,取自文档.
import numpy as np
import pandas as pd
arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),
np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])]
df = pd.DataFrame(np.random.randn(8, 4), index=arrays)
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
0 1 2 3
bar one -0.096648 -0.080298 0.859359 -0.030288
two 0.043107 -0.431791 1.923893 -1.544845
baz one 0.639951 -0.008833 -0.227000 0.042315
two 0.705281 0.446257 -1.108522 0.471676
foo one -0.579483 -2.261138 -0.826789 1.543524
two -0.358526 1.416211 1.589617 0.284130
qux one 0.498149 -0.296404 0.127512 -0.224526
two -0.286687 …
Run Code Online (Sandbox Code Playgroud) 我有一个带MultiIndex的DataFrame:
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
# dataframe with dates
dates = pd.DataFrame()
dates['2016'] = pd.date_range(start='2016', periods=4, freq='60Min')
dates['2017'] = pd.date_range(start='2017', periods=4, freq='60Min')
dates['2018'] = pd.date_range(start='2018', periods=4, freq='60Min')
dates.reset_index()
dates = dates.unstack()
# multi-indexed dataframe
df = pd.DataFrame(np.random.randn(36, 3))
df['concept'] = np.repeat(np.repeat(['A', 'B', 'C'], 3), 4)
df['datetime'] = pd.concat([dates, dates, dates], ignore_index=True)
df.set_index(['concept', 'datetime'], inplace=True)
df.sort_index(inplace=True)
df.columns = ['V1', 'V2', 'V3']
df.info()
Run Code Online (Sandbox Code Playgroud)
返回:
V1 V2 V3
concept datetime
A 2016-01-01 00:00:00 -0.303428 …
Run Code Online (Sandbox Code Playgroud) 我们使用预提交来使用黑色格式化我们的 Python 代码,并在以下配置中进行配置.pre-commit-config.yaml
:
repos:\n - repo: https://github.com/ambv/black\n rev: 20.8b1\n hooks:\n - id: black\n language_version: python3.7\n
Run Code Online (Sandbox Code Playgroud)\n由于我们的包在不同的 Python 版本(例如,,3.7
)中进行测试和使用,我希望能够在不同的 Python 版本上使用预提交 Hook。但是,当在 Python 上提交代码时,由于我的配置(见上文),我收到错误:3.8
3.9
3.8
language_version
C:\\Users\\FooBar\\Documents\\Programmierung\\foo (dev -> origin)\n\xce\xbb git commit -m "Black file with correct black version"\n[INFO] Initializing environment for https://github.com/ambv/black.\n[INFO] Installing environment for https://github.com/ambv/black.\n[INFO] Once installed this environment will be reused.\n[INFO] This may take a few minutes...\nAn unexpected error has occurred: CalledProcessError: command: (\'c:\\\\users\\\\FooBar\\\\anaconda\\\\python.exe\', \'-mvirtualenv\', …
Run Code Online (Sandbox Code Playgroud) 我使用matplotlibs ggplot样式进行绘图,并且只想覆盖特定的标准参数,例如xticklabels的颜色,网格背景颜色和线宽.
import numpy as np
import pandas as pd
import matplotlib
# changing matplotlib the default style
matplotlib.style.use('ggplot')
# dataframe plot
df = pd.DataFrame(np.random.randn(36, 3))
df.plot()
Run Code Online (Sandbox Code Playgroud)
我知道我可以设置轴对象的单个属性,如下所示:
ax.set_axis_bgcolor('red')
Run Code Online (Sandbox Code Playgroud)
但是,我如何覆盖默认的属性(例如标签颜色,背景颜色和线宽,以便在所有图中使用它们?
提前致谢!
我们正在尝试合并存储在 PostGIS 2.1 数据库中的两个多边形,而不会丢失每个多边形中包含的边界。
我们的空间数据符合以下标准。
-- Check whether the polygons share points (boundaries?)
-- ST_Intersects:
-- Returns TRUE if the Geometries/Geography "spatially intersect in 2D" - (share any portion of space)
-- and FALSE if they don't (they are Disjoint).
ST_Intersects(higher_geom,lower_geom) = TRUE
-- ST_Crosses:
-- Returns TRUE if the supplied geometries have some, but not all, interior points in common.
ST_Crosses(higher_geom,lower_geom) = FALSE
-- Since ST_Crosses would return FALSE if the polygons have all interior points in common
-- …
Run Code Online (Sandbox Code Playgroud) python ×9
pandas ×5
matplotlib ×4
anaconda ×1
git ×1
postgis ×1
pre-commit ×1
python-3.4 ×1
python-mode ×1
qgis ×1
spatial ×1
streamlit ×1
ubuntu-14.04 ×1
vim ×1