簡體   English   中英

從另一個 dataframe 的列創建 dataframe

[英]create dataframe from columns of another dataframe

我有 dataframe df ,其中包含一列check_r2 ,其中包含值TrueFalse 我想創建另一個 dataframe df1它將僅包含那些check_r2True的行

I tried with this code but getting empty dataframe as output, I am creating this dataframe from excel, where column values are in capital ie TRUE or FALSE but when I Print them using print(df) I get True or False as output, I tried比較時兩種方式,但 output 是相同的

code
df = read_data()
df1 = pd.DataFrame()
df1 = df[df['check_r2'] =="True"]

也試過

df1 = df1.append(df[df['check_r2'] =="True"])

在此處輸入圖像描述

df1 = df[df['check_r2'] ==True]

檢查數據類型

df.info()
check_r2    9 non-null bool

Pandas 正在將其轉換為 boolean。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM