如何在不同的图表中绘制一列?

时间:2016-10-18 11:23:54

标签: python pandas dataframe

我有以下问题。我有这种数据帧:

f = pd.DataFrame([['Meyer', 2], ['Mueller', 4], ['Radisch', math.nan], ['Meyer', 2],['Pavlenko', math.nan]])

是否有一种优雅的方法可以在第一列中将DataFrame拆分为多个数据帧?所以,我想得到一个数据帧,其中第一列='Müller',另一个为第一列= Radisch。

提前致谢,

埃里克

1 个答案:

答案 0 :(得分:0)

您可以使用unique循环boolean indexing列{{3}}:

A

然后使用df = pd.DataFrame([['Meyer', 2], ['Mueller', 4], ['Radisch', np.nan], ['Meyer', 2], ['Pavlenko', np.nan]]) df.columns = list("AB") print (df) A B 0 Meyer 2.0 1 Mueller 4.0 2 Radisch NaN 3 Meyer 2.0 4 Pavlenko NaN print (df.A.unique()) ['Meyer' 'Mueller' 'Radisch' 'Pavlenko'] for x in df.A.unique(): print(df[df.A == x]) A B 0 Meyer 2.0 3 Meyer 2.0 A B 1 Mueller 4.0 A B 2 Radisch NaN A B 4 Pavlenko NaN 理解 - 获取dict的{​​{1}}:

dictionary