python - 从另一个创建列
问题描述
我在 python / pandas 中有一个数据集,其中一列采用以下值:'1 - credit step'或'2 credit step'。列 ID 为 C0340。我正在尝试创建一个新的,比如 C0900,它将 1 和 2(第一个位置)作为整数。我正在使用的代码如下:
xl_file = pd.ExcelFile('C:/Users/e877780/Desktop/DEV/S2_SK_S_06_02_input.xlsx')
sheet1=xl_file.parse("S.06.02")
spread=sheet1[['C0040','C0090','C0170','C0290','C0340','C0360']]
spread['idx']=range(1,len(spread)+1)
spread.set_index('idx', inplace=True)
C0900=[]
for i in range(1, len(spread)+1):
C0900.append(int(spread.loc[i]["C0340"][:1])
spread['C0900']=C0900
spread 是列 C0340 所在的数据集,而 C0900 是我上面提到的新数据集。任何人都可以帮忙吗?
解决方案
推荐阅读
- javascript - 在 forEach 中收集 Promise 中生成的 Promise
- json - 如果未定义键,如何使用 Codable 结构表示 JSON?
- python - scikits ARI 实现中是否存在错误,或者我对算法的理解有缺陷?
- javascript - 如何让我的正则表达式用附加变量替换小写字母
- python-3.x - 如何区分护照和PAN卡在python中扫描的图像
- android - Android Emulator 如何到达本地网络上的服务器?
- javascript - 如何将变量放在引号JS中
- firebase - 从 OneSignal 迁移到 Firebase 推送通知
- sql-server - 在 SQL Server 中导入 .sqlserver 文件
- windows - 无法在 Windows 10 上更改 psql 中的目录。PostgreSQL 11