xxxxxxxxxx
import pandas as pd
# Create an example DataFrame
data = {'A': [1, 2, 3],
'B': [4, 5, 6]}
df = pd.DataFrame(data)
# Add 12 new columns with initial values
df['new_col1'] = 0
df['new_col2'] = 0
df['new_col3'] = 0
df['new_col4'] = 0
df['new_col5'] = 0
df['new_col6'] = 0
df['new_col7'] = 0
df['new_col8'] = 0
df['new_col9'] = 0
df['new_col10'] = 0
df['new_col11'] = 0
df['new_col12'] = 0
# You can also assign values to these new columns if needed
df['new_col1'] = [1, 2, 3] # Example values
df['new_col2'] = [4, 5, 6] # Example values
# Display the updated DataFrame
print(df)
xxxxxxxxxx
# 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)
# append multiple columns to Pandas DataFrame
df2 = df.assign(lost=[2, 1, 3, 4], matches_remaining=[2, 3, 1, 1])
# Print the new DataFrame
print(df2)
xxxxxxxxxx
# 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)
# insert the new column at the specific position
df.insert(3, "lost", [2, 1, 3, 4], True)
# Print the new DataFrame
print(df)
xxxxxxxxxx
# Import pandas package
import pandas as pd
# Define a dictionary containing Students data
data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Height': [5.1, 6.2, 5.1, 5.2],
'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}
# Convert the dictionary into DataFrame
df = pd.DataFrame(data)
# Declare a list that is to be converted into a column
address = ['Delhi', 'Bangalore', 'Chennai', 'Patna']
# Using 'Address' as the column name
# and equating it to the list
df['Address'] = address
# Observe the result
print(df)