Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
各行の溶媒列の値をデータ フレームの num 列の数値に設定する方法に行き詰まっています。たとえば、溶媒がノナンの場合は num を 9 に、溶媒がオクタンの場合は num を 8 にする必要があります。
.locブール値マスクで使用
.loc
df.loc[df['solvent'] == 'NONANE', 'num'] = 9 df.loc[df['solvent'] == 'OCTANE', 'num'] = 8
別の方法は、辞書を定義して呼び出すことmapです:
map
d = {'NONANE':9, 'OCTANE':8, 'HEPTANE':7, 'HEXANE':6} df['num'] = df['solvent'].map(d)