将大写字母应用于Pandas数据框中的列
示例
import pandas as pd # A dataframe df = pd.DataFrame({'Day': ['mon', 'tue', 'wed', 'thu', 'fri'],'Subject': ['Math', 'english', 'science', 'music', 'games']}) df['Day'] = df['Day'].str.upper() print(df)
输出结果
运行上面的代码给我们以下结果-
Day Subject 0 MON Math 1 TUE english 2 WED science 3 THU music 4 FRI games
示例
# A dataframe df = pd.DataFrame({'Day': ['mon', 'tue', 'wed', 'thu', 'fri'], 'Subject': ['Math', 'english', 'science', 'music', 'games']}) df1=df['Subject'].apply(lambda x: x.upper()) print(df1)
输出结果
运行上面的代码给我们以下结果-
0 MATH 1 ENGLISH 2 SCIENCE 3 MUSIC 4 GAMES Name: Subject, dtype: object