首页 > 解决方案 > 从另一个创建列

问题描述

我在 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 是我上面提到的新数据集。任何人都可以帮忙吗?

标签: pythonpandasjupyter-notebook

解决方案


推荐阅读