I have two dataframes that I created in Pandas using python. And I want to combine them into one dataframe with the columns Name, PrivateIP
and Memory
.
hosts_df:
***Hosts Data Frame:
Name PrivateIP
0 bastion001 10.238.2.166
1 logicmonitor001 10.238.2.52
2 logicmonitor002 45.21.2.1
***
memory_df:
***Memory Data Frame:
Memory
0 1843260
0 7706164
0 7904828
***
Also I want to get rid of the column of zeros in the memory_df
.
Here is my code.
code
import os
import pandas as pd
filelist = os.listdir(text_path)
# Read the servers into the DF
hosts_list = os.path.join('..', '..', 'source_files', 'aws_hosts_list', 'aws_hosts_list.csv')
text_path = "/home/tdun0002/stash/cloud_scripts/aws_scripts/output_files/memory_stats/text/"
hosts_df = pd.read_csv(hosts_list, skipinitialspace=True)
hosts_df.columns = ["Name", "PrivateIP"]
# Create the memory dataframe
column_names = ["Memory"]
memory_df = pd.DataFrame(columns=column_names)
print(f"Reading text files into the Memory DF")
for filename in filelist:
print(f"Adding filename: {filename}")
filename = text_path + filename
temp_df = pd.read_csv(filename, delim_whitespace=True, names=column_names)
memory_df = memory_df.append(temp_df)
memory_df.Memory = memory_df.Memory.astype("int32")
How can I combine these datfames into one with the columns: Name, PrivateIP, Memory
?