私信  •  关注

Quang Hoang

Quang Hoang 最近创建的主题
Quang Hoang 最近回复了
4 年前
回复了 Quang Hoang 创建的主题 » 在Python中将行值包含特定字符串移动到新列

# initialize Stats1 with empty strings
df['Stats1'] = ''

# copy values from `Stats`
df.iloc[1::2,-1] = df['Stats']

# replace the copied values with empty strings
df['Stats'] = np.where(df['Stats1'].ne(''), '', df['Stats'])

输出:

         Stats  Value            Stats1
0    Def duels    5.0                  
1                 2.5     Def duels Won
2  Back passes   60.0                  
3                55.0  Back passes[Acc]
4     Dribbles    5.0                  
5                 2.0     Dribbles[Suc]
4 年前
回复了 Quang Hoang 创建的主题 » Python子块3以2x2矩阵(金字塔)绘制

您可以将网格更改为 (2,4) colspan=2

m = np.array([[0,1],[1,0]])

fig = plt.figure()
ax = plt.subplot2grid((2,4),(0,0), colspan=2)
ax.imshow(m)
ax1 = plt.subplot2grid((2,4),(0,2), colspan=2)
ax1.imshow(m)
ax2 = plt.subplot2grid((2,4),(1,1), colspan=2)
ax2.imshow(m)

输出:

enter image description here

4 年前
回复了 Quang Hoang 创建的主题 » 数据帧中Python积分函数计算错误

语法是 integrate.trapz(y,x=None) 哪里 y x

integrate.trapz(df.Power, x=df.timestamp)
# out: 2628206.221949

还有一个相同的函数 numpy :

np.trapz(df.Power, x=df.timestamp)
# out: 2628206.221949
4 年前
回复了 Quang Hoang 创建的主题 » python/pandas-从地址中删除街道号

使用regex模式:

df['street'] = df['street'].str.replace(r'^[\d-]+', '')