I wanna do 2 similar operations with Pandas in Python 3. One with tilde and another without tilde.
1 - df = df[~(df.teste.isin(["Place"]))]
2 - df = df[(df.teste.isin(["Place"]))]
I tried to declare the tilde as variable, so I could write just one line and then decide if I wanna use with or without tilde. But it doesn't work:
tilde = ["~", ""]
df = df[tilde[0](df.teste.isin(["Place"]))]
Is possible do something that could reduce my code? Cause I am writing many equal lines just exchanging the tilde...
Thanks!
Why I wanna the tilde as variable:
def server_latam(df):
df.rename(columns={'Computer:OSI':'OSI'}, inplace=True)
df = df[~(df.teste.isin(["Place"]))]
df1 = df.loc[df.model != 'Virtual Platform', 'model'].count()
print("LATAM")
print("Physical Servers: ",df1)
df2 = df.loc[df.model == 'Virtual Platform', 'model'].count()
print("Virtual Servers: ",df2)
df3 = df.groupby('platformName').size().reset_index(name='by OS: ')
print(df3)
def server_latam_without_tilde(df):
df.rename(columns={'Computer:OSI':'OSI'}, inplace=True)
df = df[(df.teste.isin(["Place"]))]
df1 = df.loc[df.model != 'Virtual Platform', 'model'].count()
print("LATAM")
print("Physical Servers: ",df1)
df2 = df.loc[df.model == 'Virtual Platform', 'model'].count()
print("Virtual Servers: ",df2)
df3 = df.groupby('platformName').size().reset_index(name='by OS: ')
print(df3)
In the second line of each function the tilde appears.