Aytida
Aytida

Reputation: 189

Concatenate two pandas dataframe and follow a sequence of uid

I have a pandas dataframe with the following data: (in csv)

#list1
poke_id,symbol
0,BTC
1,ETB
2,USDC

#list2
5,SOL
6,XRP

I am able to concatenate them into one dataframe using the following code:

df = pd.concat([df1, df2], ignore_index = True)
df = df.reset_index(drop = True)
df['poke_id'] = df.index
df = df[['poke_id','symbol']]

which gives me the output: (in csv)

poke_id,symbol
0,BTC
1,ETB
2,USDC
3,SOL
4,XRP

Is there any other way to do the same. I think calling the whole data frame of ~4000 entries just to add ~100 more will be a little pointless and cumbersome. How can I make it in such a way that it picks list 1 (or dataframe 1) and picks the highest poke_id; and just does i + 1 to the later entries in list 2.

Upvotes: 0

Views: 147

Answers (2)

jezrael
jezrael

Reputation: 863166

Your solution is good, is possible simplify:

df = pd.concat([df1, df2], ignore_index = True).rename_axis('poke_id').reset_index()

Upvotes: 1

Sasidhar Nandigam
Sasidhar Nandigam

Reputation: 1

use indexes to get what data you want from the dataframe, although this is not effective if you want large amounts of data from the dataframe, this method allows you to take specific amounts of data from the dataframe

Upvotes: 0

Related Questions