python - 我无法遍历数据框,因为该列被读取为字符串
问题描述
这是我的示例数据框和我试图通过它的循环。我还附上了我得到的错误。
示例数据框:
x Replicate y
1 1 0.39
2 2 0.08
3 3 1.46
我的代码:
df = file[['x', 'Replicate', 'y']].copy()
df.columns = ['x', 'Replicate', 'y']
grouped = df.groupby(['Obs', 'Replicate']).mean()
######################## functions ##########################
def model(t, a, b, c):
return (a-b)* np.exp(-c*t) + b
####################### curve fitting #######################
for g in grouped:
print(type(g))
# Specify initial guess
a = g['y'].max()
b = g['y'].min()
c = 0.36
错误信息:a = g['y'].max() TypeError: string indices must be integers
解决方案
推荐阅读
- android - 未找到 com.razorpay.PaymentResultListener 的类文件
- css - 可能的 z-index 问题
- css - 写作模式:初始!= chrome 上的水平-tb
- java - 我怎样才能得到对象而不是地图地址?
- flutter - 如何使用flutter_bloc包从api获取数据
- ubuntu-18.04 - 无法使用带有错误消息的 apt 或 apt-get
- python - 在 Keras 中同时增强 X,y
- reactjs - Integration Xero in ReactJS application causes errors
- reactjs - 将 React 应用程序注入 Chrome 扩展程序时,无法在“历史记录”上执行“pushState”
- php - 在默认 var/www/html 文件夹内的实时服务器中,如果没有 index.php,codeigniter 路由将无法正常工作