擅长:python、mysql、java
<pre><code>import pandas
df = pandas.DataFrame(data={'ProjectType':['Proj 1','Proj 2','Proj 1','Proj 3'], 'Dollars_Spent':[1000, 1800,800,980], 'Employees':[10, 12, 14, 5]},columns=('ProjectType','Dollars_Spent','Employees'))
df_New = pandas.concat([df, pandas.get_dummies(df['ProjectType'])], axis=1)
print(df_New)
ProjectType Dollars_Spent Employees Proj 1 Proj 2 Proj 3
0 Proj 1 1000 10 1 0 0
1 Proj 2 1800 12 0 1 0
2 Proj 1 800 14 1 0 0
3 Proj 3 980 5 0 0 1
If there is no need of ProjectType column, then can use: del df_New ['ProjectType']
</code></pre>
<p>如果您想查找有关get_dummies的其他信息,请检查<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html" rel="nofollow noreferrer">https://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html</a></p>