Skip to content
dudas (copy)
import numpy as np
# Create an array of values from 0 to 9 using np.arange
arr_arange = np.arange(0, 10, 1)
print('Array using np.arange:', arr_arange)
# Create an array of 5 values evenly spaced between 0 and 1 using np.linspace
arr_linspace = np.linspace(0, 1, 5)
print('Array using np.linspace:', arr_linspace)import pandas as pd
# Sample DataFrames
data1 = {'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9], 'D': [10, 11, 12], 'E': [13, 14, 15]}
data2 = {'F': [16, 17, 18], 'G': [19, 20, 21], 'H': [22, 23, 24], 'I': [25, 26, 27], 'J': [28, 29, 30], 'K': [31, 32, 33]}
df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)
# Merge DataFrames
merged_df = pd.concat([df1, df2], axis=1)
# Select the first 5 columns and the 10th column
selected_columns = merged_df.iloc[:, list(range(5)) + [9]]
print(selected_columns)import pandas as pd
# First DataFrame with duplicate keys
df1 = pd.DataFrame({
'key': ['A', 'A', 'B', 'C'],
'value1': [1, 2, 3, 4]
})
# Second DataFrame
df2 = pd.DataFrame({
'key': ['A', 'B', 'C'],
'value2': [5, 6, 7]
})
# Merge DataFrames on the 'key' column
result = pd.merge(df1, df2, on='key', how='inner')
print(result)superhero_list = ['thor', 'hulk']def to_upper(heroes):
for i in heroes:
return i.upper()
print(list(to_upper(superhero_list)))[s.upper() for s in superhero_list]