在R中,一旦数据帧初始化,如何向数据帧添加新行?
到目前为止我有这个:
df<-data.frame("hi","bye")
names(df)<-c("hello","goodbye")
#I am trying to add hola and ciao as a new row
de<-data.frame("hola","ciao")
merge(df,de) #adds to the same row as new columns
#I couldnt find an rbind solution that wouldnt give me an error
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我试图按键按字母顺序排序哈希,但我似乎无法找到一种方法来创建自己的排序类.我发现下面的代码按值排序,如果它是一个整数,我试图修改它但没有任何运气.
temp["ninjas"]=36
temp["pirates"]=12
temp["cheese"]=222
temp.sort_by { |key, val| key }
Run Code Online (Sandbox Code Playgroud)
我的目标是按键排序Hash然后输出值.我将不得不使用不同的哈希顺序多次执行此操作但值相同.
这里的目标是创建一个分组的条形图,而不是如下图所示的子图
有没有一种简单的方法在Python中创建分组条形图?现在我得到了单独的条形图,而不是一个图上的单独条形图.
df = pd.DataFrame([['g1','c1',10],['g1','c2',12],['g1','c3',13],['g2','c1',8],['g2','c2',10],['g2','c3',12]],columns=['group','column','val'])
%matplotlib inline
df.groupby(['group']).plot(kind='bar')
Run Code Online (Sandbox Code Playgroud)
如何修复路由?我有一个带有Angular前端的C#项目.如果我去ac #View哪个调用Angular组件,一切都会中断.如果我调用Angular视图(直接从URL),一切正常.
C#路由到ac#视图
xxx/Home/index
这只是一个调用Angular组件的View(抛出一堆500个错误)手动路由到Angular
/anything
到url(xxx/Home/Index/anything
),Angular路由接管并且所有内容都加载正常.索引方法调用
public class HomeController : Controller
{
public IActionResult Index()
{
return View("IndexAng");
}
}
Run Code Online (Sandbox Code Playgroud)
IndexAng.cshtml
@{
ViewData["Title"] = "Home Page";
}
@*<script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>*@
@*<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>*@
<h3>Loading Ang App root:</h3>
<app-root></app-root>
<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}
Run Code Online (Sandbox Code Playgroud)
从Startup.cs配置方法
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext identityContext,
UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager)
{
#if DEBUG
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true …
Run Code Online (Sandbox Code Playgroud) 我在UserDataSource中有一个硬编码值,它没有映射到Material Data表.然而,当我将它打印到屏幕上时,我可以看到json ...我错过了什么?
更新:我发现当删除复选框列时,表格会正常填充...任何想法该列的错误是什么?
DATA: {{dataSource.data | json}}
<mat-table class="lessons-table mat-elevation-z8 overflow-x-auto" [dataSource]="dataSource">
<div class="spinner-container" *ngIf="dataSource.loading$ | async">
<mat-spinner></mat-spinner>
</div>
<!-- Checkbox Column -->
<ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox (change)="$event ? masterToggle() : null"
[checked]="selection.hasValue() && isAllSelected()"
[indeterminate]="selection.hasValue() && !isAllSelected()">
</mat-checkbox>
</th>
<td mat-cell *matCellDef="let row">
<mat-checkbox (click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)">
</mat-checkbox>
</td>
</ng-container>
<!-- end checkbox column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
<mat-cell *matCellDef="let e">tempName</mat-cell>
</ng-container>
<ng-container matColumnDef="twodigitcoid">
<mat-header-cell *matHeaderCellDef>Two digit coid</mat-header-cell>
<mat-cell *matCellDef="let e">removeme</mat-cell> …
Run Code Online (Sandbox Code Playgroud) 我正在使用Android ADT Bundle进行开发工作.在线阅读了多个指南后,我将com.dm.zbar.android.scanner软件包添加到了我的项目中.我在包中包含了CameraPreview.java,ZBarConstants.java和ZBarScannerActivity.java文件.尽管如此,类ScanActivity.java中的ZBAR_SCANNER_REQUEST var(由我创建,但使用zbar方法)无法解析为变量.接受除此变量之外的所有内容.知道为什么会这样吗?注意:我的libs文件夹包含此处的所有内容:
https://github.com/DushyanthMaguluru/ZBarScanner/tree/master/ZBarScannerLibrary/libs
和zbar.jar包含在构建路径中.
ScanActivity:
package com.xx.xxx;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;
import net.sourceforge.zbar.Symbol;
public class ScanActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
}
public void launchScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public void launchQRScanner(View v) {
if (isCameraAvailable()) {
Intent …
Run Code Online (Sandbox Code Playgroud) 我试图使用以下代码运行所有数字值之间的相关性(数据集包含数字和非数字值的列):
mydata= read.csv("C:\\full_path\\playerData.csv", header = TRUE)
mydata=data.frame(mydata)
vals=cor(mydata, use="complete.obs", method="pearson")
write.csv(vals,"C:\\Users\\weiler\\Desktop\\RStudioOutput.csv")
Run Code Online (Sandbox Code Playgroud)
基于这个网站:http://www.statmethods.net/stats/correlations.html我收到错误:
cor中的错误(mydata,use ="complete.obs",method ="pearson"):'x'必须是数字
我的错误似乎是因为某些数据是非数字的.有一种简单的方法可以忽略非数字数据吗?
我想在styles.xml中默认应用按钮文本颜色
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme">
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@color/black</item>
<item name="android:textColor">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如何制作样式更改按钮颜色,并应用于整个应用程序?我的主要节日包括:
<application
android:icon="@drawable/ic_launcher"
android:label="Hack the World"
android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)
这会更改所有文本(例如TextView),但不会更改按钮中的文本.如果我使用上面的ColorThemes样式并将其放在按钮的xml中,如下所示:
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="loadSavedgame"
android:text="Load Saved Game"
android:textColor="@color/green" />"
Run Code Online (Sandbox Code Playgroud)
然后它完美地运作.为什么这种风格不适用于普遍?styles.xml的所有不同版本都具有相同的代码.
我已经实现了onRestoreInstanceState和onSaveInstanceState.当应用程序最小化时(通过按主页按钮,或其他活动位于前台),它们都能成功运行.但是,当我最小化应用程序并终止进程时(通过打开当前进程列表并结束该进程),应用程序不会还原已保存的实例状态.如何让它恢复保存的状态?我是使用serializable将savedInstanceState包写入文件的最佳选择(因此将某些内容存储在硬盘驱动器上,而不是RAM中),然后从文件中重新加载savedInstanceState?
我试图在Pandas数据帧中取消堆栈()数据,但我不断收到此错误,我不知道为什么.到目前为止,我的代码是我的数据样本.我尝试修复它的方法是删除所有的行,其中voteId不是数字,这对我的实际数据集不起作用.这种情况发生在Anaconda笔记本(我正在开发的地方)和我的生产环境中,当我部署代码时.
我无法弄清楚如何在我的示例代码中重现错误...可能是由于在实例化数据帧时不存在的类型转换问题,就像我在示例中所做的那样?
#dataset simulate likely input
# d = {'vote': [100, 50,1,23,55,67,89,44],
# 'vote2': [10, 2,18,26,77,99,9,40],
# 'ballot1': ['a','b','a','a','b','a','c','c'],
# 'voteId':[1,2,3,4,5,'aaa',7,'NaN']}
# df1=pd.DataFrame(d)
#########################################################
df1=df1.drop_duplicates(['voteId','ballot1'],keep='last')
s=df1[:10].set_index(['voteId','ballot1'],verify_integrity=True).unstack()
s.columns=s.columns.map('(ballot1={0[1]}){0[0]}'.format)
dflw=pd.DataFrame(s)
Run Code Online (Sandbox Code Playgroud)
完整错误消息/堆栈跟踪:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-10-0a520180a8d9> in <module>()
22 df1=df1.drop_duplicates(['voteId','ballot1'],keep='last')
23
---> 24 s=df1[:10].set_index(['voteId','ballot1'],verify_integrity=True).unstack()
25 s.columns=s.columns.map('(ballot1={0[1]}){0[0]}'.format)
26 dflw=pd.DataFrame(s)
~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in unstack(self, level, fill_value)
4567 """
4568 from pandas.core.reshape.reshape import unstack
-> 4569 return unstack(self, level, fill_value)
4570
4571 _shared_docs['melt'] = ("""
~/anaconda3/lib/python3.6/site-packages/pandas/core/reshape/reshape.py in unstack(obj, level, fill_value)
467 if isinstance(obj, …
Run Code Online (Sandbox Code Playgroud) android ×3
angular ×2
pandas ×2
python ×2
r ×2
background ×1
bar-chart ×1
button ×1
c# ×1
correlation ×1
dataframe ×1
import ×1
matplotlib ×1
python-3.x ×1
reload ×1
routing ×1
ruby ×1
savestate ×1
serializable ×1
sorting ×1
xml ×1
zbar ×1