我有一个包含 96 列的数据框:
df.to_csv('result.csv')
Run Code Online (Sandbox Code Playgroud)
出(优秀):
Run 1 Run 2 Run 3 Run 4 Run 5 Run 6 Run 7 Run 8 Run 9 Run 10 Run 11 Run 12 Run 13 Run 14 Run 15 Run 16 Run 17 Run 18 Run 19 Run 20 Run 21 Run 22 Run 23 Run 24 Run 25 Run 26 Run 27 Run 28 Run 29 Run 30 Run 31 Run 32 Run 33 Run 34 Run 35 Run 36 Run 37 Run …Run Code Online (Sandbox Code Playgroud) 这可能吗?我有一个基本的等式:
Q = (pi*(Ta-Ts))/(((1/ha*Do))+(1/(2*k))*math.log(Do/Di)) * L
where;
ha = 8.14
k = 0.0026
Do = 0.2
Di = 0.003175
L = 0.25
F = 0.0704
Ta = 293
Ts = 113
pi = 3.14159265
Run Code Online (Sandbox Code Playgroud)
我想看看一些变量如何影响最终输出(并构建一个变量灵敏度表).我已经以图表格式管理了这个,但想要一些描述性的统计数据.
例如,我想将Do(外径)作为范围np.arange(0.1,2,100)并保持其他变量不变.
我有以下代码来创建一些这样的图:
def enthalpy_mod1(ambient_temp, LNG_temp, Flow):
ha = 8.14
k = 0.0026
Do = 0.2
Di = 0.003175
L = 0.25
F = Flow
Ta = ambient_temp
Ts = LNG_temp
pi = 3.14159265
Q = (pi*(Ta-Ts))/(((1/ha*Do))+(1/(2*k))*math.log(Do/Di)) * L
e = (Q*3600)/F
results.append(e) # append the …Run Code Online (Sandbox Code Playgroud) 我正在尝试按行而不是按列对 pandas 数据框进行洗牌。
我有以下数据框:
row1 row2 row3
1 3 1 6
2 5 2 7
3 7 3 8
4 9 4 9
Run Code Online (Sandbox Code Playgroud)
并希望对 df 进行洗牌以实现随机排列,例如:
row1 row2 row3
1 6 3 1
2 3 9 2
3 7 5 8
4 4 9 7
Run Code Online (Sandbox Code Playgroud)
我试过:
df1 = df.reindex(np.random.permutation(df.index))
Run Code Online (Sandbox Code Playgroud)
但是,这仅按列排列,而不按行排列。
我正在尝试生成具有两种颜色的 3D 绘图。一种颜色表示大于零的值,另一种颜色表示小于零的值。我只是不知道如何在代码中实现这一点。
这是我当前的代码:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import matplotlib.tri as mtri
import pandas as pd
import numpy as np
df = pd.DataFrame.from_csv('...temp\\3ddata.csv', sep = ',', index_col = False)
fig = plt.figure()
ax = fig.gca(projection='3d')
x = df['P']
y = df['T']
z = df['S']
ax.plot(x, y, zs= 0, zdir = 'z', c= 'r')
ax.scatter(x,y, z, c = 'b', s = 20)
ax.set_xlabel('Pressure (Bar)')
ax.set_zlabel('Residual subcooling (J*Kg-1*K-1')
ax.set_ylabel('Temperaure of LNG (K)')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我已经阅读了一些示例,但无法将它们应用到我的数据中。是否可以用 …
我正在尝试编写一个简单的程序来批量重命名文件夹中的文件。
文件格式:
11170_tcd001-20160824-094716.txt
11170_tcd001-20160824-094716.rst
11170_tcd001-20160824-094716.raw
Run Code Online (Sandbox Code Playgroud)
我在上面的48个字符中,第一个“-”之后有一个不同的14位字符配置。
我的最终目标是将以上内容转换为:
11170_tcd001.txt
11170_tcd001.rst
11170_tcd001.raw
Run Code Online (Sandbox Code Playgroud)
我知道可以在python中使用os.rename文件。但是,我不知道如何使用不同的字符配置批量重命名多个文件。
这可能吗?
下面是我想要实现的一些伪代码。
import os
pathiter = (os.path.join(root, filename)
for root, _, filenames in os.walk(folder)
for filename in filenames
)
for path in pathiter:
newname = path.replace('14 digits.txt', ' 0 digits.txt')
if newname != path:
os.rename(path,newname)
Run Code Online (Sandbox Code Playgroud) 是否可以用速记写下:
x = [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
Run Code Online (Sandbox Code Playgroud)
如说
x = ([0.5]*12)?
Run Code Online (Sandbox Code Playgroud) python ×6
pandas ×3
numpy ×2
batch-rename ×1
dataframe ×1
matplotlib ×1
parameters ×1
shorthand ×1
shuffle ×1
statistics ×1