import pandas as pd
eu_weather_df = pd.DataFrame({
"town": ["Atina", "Oslo", "London"],
"temp":[35,21,25],
"rain": [False, False, True ]
})
eu_weather_df
bg_weather_df = pd.DataFrame({
"town": ["Sofia", "Sandanski", "Pleven"],
"temp":[25,32,21],
"rain": [False, False, True ]
})
bg_weather_df
cols = ["town", "temp", "rain"]
eu_weather_df = eu_weather_df[cols]
eu_weather_df
bg_weather_df = bg_weather_df[cols]
bg_weather_df
The simplest, and most commmon way is with [] operator. But you can use .insert or .loc methods
eu_weather_df["wind"]= [1.5, 7.5, 4]
eu_weather_df
wind_df=pd.DataFrame([3.4, 2,6.5], columns=["wind"])
wind_df
bg_weather_df_copy = bg_weather_df.copy()
bg_weather_df_copy
bg_weather_df_copy_conc = pd.concat([bg_weather_df_copy, wind_df],axis=1)
bg_weather_df_copy_conc
eu_weather_df
df_tmp = eu_weather_df.copy()
del df_tmp["wind"]
df_tmp
df_tmp = eu_weather_df.drop(["wind","rain"], axis=1)
df_tmp
# keep indexes:
appended_weather = eu_weather_df.append(bg_weather_df)
#auto indexing
# appended_weather = eu_weather_df.append(bg_weather_df,ignore_index=True)
appended_weather
# keep indexes
concat_weather = pd.concat([eu_weather_df, bg_weather_df])
# auto indexing:
# concat_weather = pd.concat([eu_weather_df, bg_weather_df], ignore_index=True)
# add keys for each DF
concat_weather = pd.concat([eu_weather_df, bg_weather_df],keys=["EU", "BG"])
# retrieve by index location:
# concat_weather.loc["BG"]
concat_weather
print(eu_weather_df)
print(bg_weather_df)
concat_weather_as_columns = pd.concat([eu_weather_df, bg_weather_df], axis=1)
concat_weather_as_columns
print(bg_weather_df)
bg_weather_df.describe()
print(bg_weather_df)
print("***count:\n", bg_weather_df.count())
print("***min:\n", bg_weather_df.min())
print("***std:\n", bg_weather_df.std())