how to concat on the basis of particular columns in pandas
In [6]: result = pd.concat(frames, keys=['x', 'y', 'z'])
how to concat on the basis of particular columns in pandas
In [6]: result = pd.concat(frames, keys=['x', 'y', 'z'])
Adding new column to existing DataFrame in Pandas using concat method
# import pandas library
import pandas as pd
# create pandas DataFrame
df = pd.DataFrame({'team': ['India', 'South Africa', 'New Zealand', 'England'],
'points': [10, 8, 3, 5],
'runrate': [0.5, 1.4, 2, -0.6],
'wins': [5, 4, 2, 2]})
# print the DataFrame
print(df)
# create a new DataFrame
df2 = pd.DataFrame([[1, 2], [2, 1], [3, 4], [0, 3]],
columns=['matches_left', 'lost'])
# concat and Print the new DataFrame
print(pd.concat([df, df2], axis=1))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us