I'm newbie in data engineer. now i try to write python code for duplicate data from from pandas dataframe. for example data:
A B C D E F G E
1 2 3 4 0 1 0 1
5 6 7 8 0 1 1 0
9 1 2 3 0 1 0 1
I need to copy dataframe to
dfE = A B C D E
1 2 3 4 0
5 6 7 8 0
9 1 2 3 0
dfF = A B C D F
1 2 3 4 1
5 6 7 8 1
9 1 2 3 1
dfG...
Help me please...
Hi piyaphong welcome to stackoverflow,
Basically pandas allow to select columns with column names, you can look at the code below which would probably solve your case.
from io import StringIO
import pandas as pd
data = """
A B C D E F G E
1 2 3 4 0 1 0 1
5 6 7 8 0 1 1 0
9 1 2 3 0 1 0 1
"""
df = pd.read_csv(StringIO(data), sep=' ')
dfE = df[['A', 'B', 'C', 'D', 'E']]
dfF = df[['A', 'B', 'C', 'D', 'F']]
dfG = df[['A', 'B', 'C', 'D', 'G']]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.