我想将dataframe中的首字母大写。
大专学历
如果此代码:
df ['education'] = df ['education']。str.title()作为结果
大专学历。
如何在不使用大写字母的情况下拥有良好的代码
大专学历。
最佳答案
另一种选择是使用string.capwords:
import string
import pandas as pd
df = pd.DataFrame(data=["associate's degree"], columns=['education'])
print(df['education'].apply(string.capwords))
输出量
0 Associate's Degree
Name: education, dtype: object
关于python - 如何在不大写()的情况下对数据框进行title(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53696079/