以下是我的数据框
import pandas as pd
df = pd.DataFrame({'name': ['jon','sam','jane','bob'],
'age': [30,25,18,26],
'sex':['male','male','female','male']})
age name sex
0 30 jon male
1 25 sam male
2 18 jane female
3 26 bob male
Run Code Online (Sandbox Code Playgroud)
我想在第一个位置插入一个新行
姓名:院长,年龄:45岁,性别:男
age name sex
0 45 dean male
1 30 jon male
2 25 sam male
3 18 jane female
4 26 bob male
Run Code Online (Sandbox Code Playgroud)
在熊猫中做到这一点的最佳方法是什么?
我正在尝试使用lazy参数构建一个格式字符串,例如我需要像:
"%s \%s %s" % ('foo', 'bar') # "foo %s bar"
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我是使用Matplotlib制作外观漂亮的Seaborn包的粉丝.但我似乎无法弄清楚如何在我的情节中显示小网格线.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sbn
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
fig, ax = plt.subplots(1, 1)
ax.scatter(x, y)
ax.grid(b=True, which='major')
ax.grid(b=True, which='minor')
Run Code Online (Sandbox Code Playgroud)
得到:
这有什么想法?还有任何关于如何调整Seaborn网格线的风格的想法......特别是,我喜欢让它们更窄.
我想在屏幕右下角的native native android中使用浮动操作按钮.但我无法这样做.
所述CreateButton成分含有浮动按钮的代码.我在List View之后调用了CreateButton组件,我想在ListView android组件上显示这个按钮,透明覆盖和右下角的固定位置.
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={() => navigationView}>
<View style={styles.navBar}>
<TouchableOpacity style={styles.menuIconButton}>
<Image style={styles.menuIcon} source={{uri : 'https://cdn1.iconfinder.com/data/icons/basic-ui-elements-plain/422/ 06_menu_stack-128.png'}}/>
</TouchableOpacity>
<Text style={styles.appName}>LifeMaker</Text>
<TouchableOpacity style={styles.smokeIconButton}>
<Image style={styles.smokeIcon} source={{uri : 'http://avtech.com/images/home/icons/Icon_Smoke_&_Fire.png'}}/>
</TouchableOpacity>
</View>
<ToolbarAndroid
title="AwesomeApp"
onActionSelected={this.onActionSelected}/>
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderSmokeSignals}/>
<CreateButton/> //this is floating button component call
</DrawerLayoutAndroid>
//this is floating button component (<CreateButton>)
<View style={styles.createButton}>
<AccentColoredFab>
<Icon
name='ion|plus'
size={25}
color='#000000'
style={styles.icon}
/>
</AccentColoredFab>
</View>
Run Code Online (Sandbox Code Playgroud) 我必须使用matplotlib并排绘制饼图和表格.
为绘制饼图,我使用以下代码:
import matplotlib.pyplot as plt
df1.EventLogs.value_counts(sort=False).plot.pie()
plt.show()
Run Code Online (Sandbox Code Playgroud)
为了绘制表格,我使用以下代码:
%%chart table --fields MachineName --data df_result2
Run Code Online (Sandbox Code Playgroud)
df_result2是一个包含MachineName列表的表.
不确定我们是否可以并排放置饼图和表格.任何帮助,将不胜感激.
我正在尝试创建一个图,但我只想让ticklabels显示如上所示的对数比例.我只希望显示50,500和2000的次要标签.无论如何指定要显示的次要刻度标签?我一直试图解决这个问题,但没有找到一个好的解决方案.我能想到的就是获取minorticklabels()并将fontsize设置为0.这显示在第一段代码下面.我希望有一个更清洁的解决方案.
另一件事是改变颜色栏中的勾选标签的大小,我还没想到.如果有人知道这样做的方法,请告诉我,因为我没有看到颜色栏中的方法很容易做到这一点.
第一个代码:
fig = figure(figto)
ax = fig.add_subplot(111)
actShape = activationTrace.shape
semitones = arange(actShape[1])
freqArray = arange(actShape[0])
X,Y = meshgrid(self.testFreqArray,self.testFreqArray)
Z = sum(activationTrace[:,:,beg:end],axis=2)
surf = ax.contourf(X,Y,Z, 8, cmap=cm.jet)
ax.set_position([0.12,0.15,.8,.8])
ax.set_ylabel('Log Frequency (Hz)')
ax.set_xlabel('Log Frequency (Hz)')
ax.set_xscale('log')
ax.set_yscale('log')
ax.xaxis.set_minor_formatter(FormatStrFormatter('%d'))
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.tick_params(axis='both',reset=False,which='both',length=8,width=2)
self.plotSetAxisLabels(ax,22)
self.plotSetAxisTickLabels(ax,18)
cbar = fig.colorbar(surf, shrink=0.5, aspect=20, fraction=.12,pad=.02)
cbar.set_label('Activation',size=18)
return ax, cbar
Run Code Online (Sandbox Code Playgroud)
第二代码:
fig = figure(figto)
ax = fig.add_subplot(111)
actShape = activationTrace.shape
semitones = arange(actShape[1])
freqArray = arange(actShape[0])
X,Y = meshgrid(self.testFreqArray,self.testFreqArray)
Z = sum(activationTrace[:,:,beg:end],axis=2)
surf = ax.contourf(X,Y,Z, 8, …
Run Code Online (Sandbox Code Playgroud) seaborn stripplot具有允许的功能hue
.
使用https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html中的示例
import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.stripplot(x=tips["total_bill"])
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,图例非常小,每天显示不同的色调.但是,我想删除传说.
通常,一个包括参数legend=False
.但是,对于stripplot
,这似乎输出属性错误:
AttributeError: Unknown property legend
Run Code Online (Sandbox Code Playgroud)
可以删除传说stripplots
吗?如果是这样,那怎么做呢?
在numpy操作中,我有两个向量,假设向量A是4X1,向量B是1X5,如果我做AXB,它应该得到一个大小为4X5的矩阵.
但我尝试了很多次,进行了多种重塑和转置,它们都会引发错误,说不对齐或返回单个值.
我应该如何得到我想要的矩阵的输出产品?
我正在尝试使用matplotlib
100000000个数据点渲染图像,它会产生错误OverflowError: In draw_path: Exceeded cell block limit
.它可以绘制的数据点数量是否有限制?
我有两个图表,其中两个具有相同的x轴,但具有不同的y轴标度.
具有常规轴的图是具有描绘衰减的趋势线的数据,而y半对数缩放描绘了拟合的准确性.
fig1 = plt.figure(figsize=(15,6))
ax1 = fig1.add_subplot(111)
# Plot of the decay model
ax1.plot(FreqTime1,DecayCount1, '.', color='mediumaquamarine')
# Plot of the optimized fit
ax1.plot(x1, y1M, '-k', label='Fitting Function: $f(t) = %.3f e^{%.3f\t} \
%+.3f$' % (aR1,kR1,bR1))
ax1.set_xlabel('Time (sec)')
ax1.set_ylabel('Count')
ax1.set_title('Run 1 of Cesium-137 Decay')
# Allows me to change scales
# ax1.set_yscale('log')
ax1.legend(bbox_to_anchor=(1.0, 1.0), prop={'size':15}, fancybox=True, shadow=True)
Run Code Online (Sandbox Code Playgroud)
现在,我正试着像这个链接http://matplotlib.org/examples/pylab_examples/subplots_demo.html提供的示例一样努力实现两者.
特别是这一个
在查看示例的代码时,我对如何植入3件事情感到有点困惑:
1)以不同方式缩放轴
2)保持指数衰减图的图形大小相同,但是线图具有较小的y尺寸和相同的x尺寸.
例如:
3)保持函数的标签仅出现在衰减图中.
非常感激任何的帮助.
python ×9
matplotlib ×6
pandas ×3
numpy ×2
seaborn ×2
legend ×1
matrix ×1
python-3.x ×1
react-native ×1
scipy ×1
subplot ×1
vector ×1