Home > database >  Slice / split Pandas Dataframe
Slice / split Pandas Dataframe

Time:06-16

How do take a dataframe with 10 columns labelled Apple, Bee, Charlie, Dino, Echo, Free, Guitar, Hello, Ignite, June and create a new data from it with a select few of the column - for example a dataframe with 2 of the columns Apple and Echo and then another dataframe with 3 of the columns Guitar, Hello and Bee.

CodePudding user response:

df1 = df[['Apple', 'Bee']]
df2 = df[['Guitar', 'Hello', 'Bee']]

CodePudding user response:

So you learn how to run iloc, then pandas concat. These will help you I guess. Since the sample of the question isn't clear, I suggest you look here.

If this help you, try it:

import pandas as pd
df = pd.DataFrame(columns=("A","B","C","D"))
df2 = df.iloc[:,:2]

It will show the only first 2 column.

  • Related