这个问题在这里已有答案:
我想将多个列连接成一列。
我的列标签名为“comments”,“comment1”和“comment2”。在每个列中,我希望将值连接在一起。
下面给出了我的熊猫df外观的一个例子。
“名称”,“注释”,“注释1”,“注释2”都是单独的列。
我的目标是将所有值存储在一列中。
Name Comment Comment1 Comment2
Tyler No antibiotics given to student.
Halsey 21 year old received prescriptions
Jamison No medications given to student today NaN NaN
所以它看起来像这样:
Name Comment
Tyler No antibiotics given to student.
Halsey 21 year old received prescriptions
Jamison No medications given to student today.
我也希望消除NaN值。
发布于 2019-06-27 16:24:28
这对我有用。
import pandas as pd
import numpy as np
df = pd.DataFrame({'Name':['Alena', 'Bruce'],