我有一个Pandas DataFrame,我希望将'lat'和'long'列组合成一个元组.
<class 'pandas.core.frame.DataFrame'>
Int64Index: 205482 entries, 0 to 209018
Data columns:
Month 205482 non-null values
Reported by 205482 non-null values
Falls within 205482 non-null values
Easting 205482 non-null values
Northing 205482 non-null values
Location 205482 non-null values
Crime type 205482 non-null values
long 205482 non-null values
lat 205482 non-null values
dtypes: float64(4), object(5)
Run Code Online (Sandbox Code Playgroud)
我试图使用的代码是:
def merge_two_cols(series):
return (series['lat'], series['long'])
sample['lat_long'] = sample.apply(merge_two_cols, axis=1)
Run Code Online (Sandbox Code Playgroud)
但是,这返回了以下错误:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-261-e752e52a96e6> in <module>()
2 return (series['lat'], series['long'])
3 …Run Code Online (Sandbox Code Playgroud) 我正在使用csv,不幸的是,它使用42705的数字格式记录了日期时间,尽管它应该是2016年12月1日.
我想使用Lubridate或其他软件包将其转换为R中的正确格式.有没有能够处理它的功能?
当我单击提交按钮时,如何在尝试从AJAX调用中获取数据并将其插入另一个函数时,如何避免以下错误?
ajax函数中的console.log调用显示数据被抓取,我希望然后存储在json_data中.
然后,目的是使用此数据来更改通过HTML表单提交的字符串.
然后在"click"函数的行返回错误:
console.log(json_data.length);
Run Code Online (Sandbox Code Playgroud)
<title>Test Form</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<style>
#results_box {
border: red 5px solid;
}
#place {
border: #cccccc 1px solid;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
var json_source = "https://spreadsheets.google.com/feeds/list/0ApL1zT2P00q5dG1wOUMzSlNVV3VRV2pwQ2Fnbmt3M0E/od7/public/basic?alt=json";
var string_data ="";
var json_data = $.ajax({
dataType: 'jsonp',
url: json_source,
success: function(data){
var data_obj = [];
for (i=0; i<data.feed.entry.length; i++){
var el = {'key': data.feed.entry[i].title['$t'], 'value': '<p><a href="'+data.feed.entry[i].content['$t']+'>'+data.feed.entry[i].title['$t']+'</a></p>'};
data_obj.push(el)};
console.log("data grabbed");
return data_obj;
},
error: function(jqXHR, textStatus, errorThrown){
$('#results_box').html('<h2>Something went wrong!</h2><p><b>' + textStatus + '</b> …Run Code Online (Sandbox Code Playgroud) 我有Sublime Text 2的问题,当我启动它时会自动尝试加载导致它崩溃的文件.
我可以看到有些方法可以在设置加载后更改设置 - 如何在无法完成启动时修复它?
我在Mac OSX(Mavericks)上运行.
另一个新手查询.我一直在努力为Python项目安装matplotlib,因此阅读建议的Homebrew是一个可靠的包管理和依赖项解决方案.
但是,当我运行Homebrew诊断程序时,我收到以下错误:
$ brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: /usr/bin occurs before /usr/local/bin …Run Code Online (Sandbox Code Playgroud) 我在Scikit-Learn中构建了一个管道,其中包括两个步骤:一个构建要素,第二个是RandomForestClassifier.
虽然我可以保存该管道,但是查看各个步骤以及步骤中设置的各种参数,我希望能够从结果模型中检查要素重要性.
那可能吗?
早上好,
我已经学习了两三个月的Python,但现在发现我的2.7安装存在一些问题,因为我已经研究过像nltk这样的模块.
但是,当我想使用帮助("模块")列出模块时,我有一个主要错误,我认为解释的问题是:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg/setuptools/command/install_scripts.py:3: UserWarning: Module numpy was already imported from /Library/Python/2.7/site-packages/numpy-override/numpy/__init__.pyc, but /Library/Python/2.7/site-packages/numpy-1.8.0.dev_5c944b9_20120828-py2.7-macosx-10.8-x86_64.egg is being added to sys.path
from pkg_resources import Distribution, PathMetadata, ensure_directory
Run Code Online (Sandbox Code Playgroud)
我还收到与已弃用的模块有关的以下错误:
/Library/Python/2.7/site-packages/statsmodels-0.5.0-py2.7-macosx-10.8-intel.egg/scikits/statsmodels/__init__.py:2: UserWarning: scikits.statsmodels namespace is deprecated and will be removed in 0.5, please use statsmodels instead
Run Code Online (Sandbox Code Playgroud)
我仍然试图抓住路径并想知道是否有人可以帮助我避免将来出现这个问题.谢谢.
我试图安装Matplot lib,但我仍然在努力克服错误.
我安装了numpy和psipy,但是当我使用easy_install时出现以下错误(与pip有类似的错误).
是的,我已经在Xcode中安装了命令行工具,以解决'gcc-4.2 not found'问题.
pymods ['pylab']
packages ['matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor',
'matplotlib.projections', 'matplotlib.testing', 'matplotlib.testing.jpl_units',
'matplotlib.tests', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid',
'mpl_toolkits.axes_grid1', 'mpl_toolkits.axisartist', 'matplotlib.sphinxext',
'matplotlib.tri', 'matplotlib.delaunay', 'pytz', 'dateutil', 'dateutil.zoneinfo']
warning: no files found matching 'KNOWN_BUGS'
warning: no files found matching 'INTERACTIVE'
warning: no files found matching 'MANIFEST'
warning: no files found matching '__init__.py'
warning: no files found matching 'examples/data/*'
warning: no files found matching 'lib/mpl_toolkits'
warning: no files found matching 'LICENSE*' under directory 'license'
gcc-4.2 not found, using clang instead
In file …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个简单的汇总函数来加速报告多列数据以用于R Markdown文件.
var1是数据的分类列,t_var是表示数据四分之一的整数,dt是完整数据.
summarise_data_categorical <- function(var1, t_var, dt){
print(var1)
print(t_var)
#Select the columns to aggregate
group_func <- dt %>%
select(one_of(t_var, var1)) %>%
group_by(t_var,var1)
#create simple count summary
count_table <- group_func %>%
summarise(count = n()) %>%
spread(t_var, count)
#create a frequency version of the same table...
freq <- dt %>%
select(t_var, var1) %>%
group_by(t_var,var1) %>%
summarise(count = n()) %>%
mutate(freq = round(count / sum(count),3)*100) %>%
select(-count)
#Present that table
freq_table <- freq %>%
spread(t_var, freq)
#Create the chart to do the …Run Code Online (Sandbox Code Playgroud) 我有20,000张矩形图像,我想对它们进行中心裁剪,以便将它们插入机器学习算法中。
Tensorflow有tf.image.central_crop(),但是我想在TF介入之前检查图片。该函数采用张量并输出张量。
在Python中裁剪它们的最佳工具是什么?
编辑:或者,什么是计算中心作物的最佳算法?
python ×5
macos ×2
matplotlib ×2
r ×2
clang ×1
dataframe ×1
deprecated ×1
dplyr ×1
function ×1
homebrew ×1
image ×1
javascript ×1
jquery ×1
json ×1
lubridate ×1
numpy ×1
pandas ×1
path ×1
scikit-learn ×1
scope ×1
statsmodels ×1
sublimetext2 ×1
tensorflow ×1
tuples ×1
xcode ×1