In: Computer Science
How do you split a pandas column with floating numbers on a symbol. For example:
COLUMN = Location
ROW = 44.567892, -83.783937
Split the numbers into two separate columns based off of the comma. Meaning 44.567892 would be in its own column and -83.783937 would be in its own column. In python
Hello
Code:
# import Pandas as pd
import pandas as pd
# Read from the csv file
data = pd.read_csv("split_input.csv")
# Convert data to dict
data_dict = data.to_dict()
# Create a new data frame
df = pd.DataFrame(data_dict)
# By default splitting is done on the basis of single space.
split_df = df.Row.str.split(expand=True)
# Output to a csv file
split_df.to_csv("output_split.csv")
Code_Snippet:
Output (In CSV File):