[英]Pandas Create dataframe keeping only columns from another dataframe and appending
[英]create dataframe from columns of another dataframe
我有 dataframe df ,其中包含一列check_r2
,其中包含值True
或False
。 我想創建另一個 dataframe df1
它將僅包含那些check_r2
為True
的行
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.