What I have:
df = pd.DataFrame(data = ["version11.11","version2.2","version3"], columns=["software_version"])
Index software_version
0 version11.11
1 version2.2
2 version3
What I am trying to do:
Is to detect the type of the second last character in the dataframe column called software_version and create a new column in the dataframe based on that condition.
If the second last character is a digit or an alphabet, extract the whole name without the last alpha/digital. Such as version11.11 becomes version11.1 OR version3 becomes version. elif, its a decimal place then extract til before the decimal place, version2.2 becomes version2
Output Should be:
Index software_version main_software
0 version11.11 version11.1
1 version2.2 version2
2 version3 version
What I did so far:
How can I cleanly add the column above main_software ?
import pandas as pd
df = pd.DataFrame(data = ["version11.11","version2.2","version3"], columns=["software_version"])
for name in df.software_version:
if name[-2].isalnum():
print(name[:-1])
elif name[-2] == ".":
print(name[:-2])
else :
print("!Alphanum-dot")