[英]python - combining and interpolating 2 dataframe column and creating unique number list from it
[英]Extracting unique list of strings from Python Dataframe column
我有一個示例數據框,如下所示:
df =
index Value Name
2019-01-01 07:53:53 10 S_1.M_01
2019-01-01 08:33:52 20 S_1.M_02
2019-01-01 09:13:52 30 S_1.M_03
2019-01-01 09:53:52 40 S_1.M_01
2019-01-01 10:33:52 50 S_1.M_02
2019-01-01 11:13:53 60 S_1.M_03
... ... ...
2019-09-08 15:38:52 100 8157_S2
現在,我要提取名稱為Name
那些列並創建輸出。 如何提取那些具有相同名稱的行?
我的代碼:
df_grp = iv_df['element'].unique
這沒有產生任何結果。
我想在不同的輸出下實現這樣的事情
輸出1:
index Value Name
2019-01-01 07:53:53 10 S_1.M_01
2019-01-01 09:53:52 40 S_1.M_01
輸出2:
index Value Name
2019-01-01 08:33:52 20 S_1.M_02
2019-01-01 10:33:52 50 S_1.M_02
OUTPUT3:
index Value Name
2019-01-01 09:13:52 30 S_1.M_03
2019-01-01 11:13:53 60 S_1.M_03
如何實現呢?
我認為您的問題中可能缺少代碼,或者不清楚,或者我沒有完全理解它。 但是您可以嘗試類似的操作,在其中遍歷唯一值並創建新的dfs。
dfs = []
for val in df.Name.unique():
dfs.append(df.loc[df.Name == val, :])
這將為您提供一個列表df,其中填充了較小的df,這些只是較大的df的摘錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.