从pandas dataframe中的现有列创建新列可以使用以下方法:
df['total'] = df['column1'] + df['column2']
df['length'] = df['column3'].apply(len)
df['category'] = np.where(df['column4'] > 0, 'positive', 'negative')
df['uppercase'] = df['column5'].str.upper()
df['average'] = df['column6'].mean()
以上是从pandas dataframe中的现有列创建新列的几种常见方法。根据具体需求和数据类型,可以选择适合的方法来创建新列。
DB TALK 技术分享会
DBTalk
云+社区技术沙龙[第9期]
云+社区技术沙龙[第27期]
云+社区技术沙龙[第15期]
云+社区开发者大会(北京站)
数字化产业研学会第一期
云+社区技术沙龙[第10期]
领取专属 10元无门槛券
手把手带您无忧上云