Pandas DataFrame

15]:

#import libraris
from datetime import datetime
import pandas as pd

In [16]:

#Make sample dataFrame
df = pd.DataFrame()
df["col_A"] = [1,2,3,4,5]
df["col_B"] = [2,4,6,8,10]
print(df)
​

col_A  col_B
0      1      2
1      2      4
2      3      6
3      4      8
4      5     10
In [17]:

#Extract specific column
col_A = df[["col_A"]]
print(col_A)

col_A
0      1
1      2
2      3
3      4
4      5
In [18]:

#you can also extract specific column like below
col_A = df.loc[:,["col_A"]]
print(col_A)

col_A
0      1
1      2
2      3
3      4
4      5
In [19]:

#Extract specific column with list
col_A_list = (df[["col_A"]].values.flatten())
print(col_A_list)

[1 2 3 4 5]
In [20]:

#Extract specific column data wich matches the conditions
col_A_list_match = df[df["col_A"]>=3]
print(col_A_list_match)

col_A  col_B
2      3      6
3      4      8
4      5     10

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です