Question

In: Computer Science

How do you split a pandas column with floating numbers on a symbol. For example: COLUMN...

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

Solutions

Expert Solution

Hello

  • As described in the problem above, ROW = 44.567892, -83.783937, it exists in a .csv file as shown below.
  • And we need to split this into multiple columns as below.
  • The code below has been written in Python 3. Input file name is "split_input.csv" and Output file name is "output_split.csv"
  • Below is the code with appropriate commnets for your better understanding. Also the code snippet for indentation purposes.
    The output would be similar as second point.

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):


Related Solutions

How do I select every row in pandas dataframe?
How do I select every row in pandas dataframe?
Describe, using words and drawings, how you would build a circuit to add floating point numbers.
Describe, using words and drawings, how you would build a circuit to add floating point numbers.
In Excel: How do I turn a series of dates into a sequence of numbers (example...
In Excel: How do I turn a series of dates into a sequence of numbers (example 1,2, 3)?
How do I assign the resulting numbers from row and column in this function: def PlacePlayer(board,player):...
How do I assign the resulting numbers from row and column in this function: def PlacePlayer(board,player): row = DieRoller(1,6) col = DieRoller(1,6) board[row][col] = 'player' return board,player To the player['row'] and player['col'] in this function in place of the 0s: def GenPlayer(level): player = {} player['name'] = GenName() player['history'] = GenHistory() #history player['attack'] = DieRoller(3,6) + DieRoller(level,4) player['defense'] = DieRoller(3,6) + DieRoller(level,4) player['health'] = DieRoller(5,6) + DieRoller(level,4) player['row'] = 0 player['col'] = 0
Do you think how the world is viewed in the way of Sperry's split brain research...
Do you think how the world is viewed in the way of Sperry's split brain research can be beneficial in any way?
How do you calculate ANOVA with uneven sets of numbers?
How do you calculate ANOVA with uneven sets of numbers?
How do you see the world around you in a physical sense? Where do you numbers...
How do you see the world around you in a physical sense? Where do you numbers and units come into play for you on a daily ?
By gel electrophoresis, how do you know if your protein binded to the column? How would...
By gel electrophoresis, how do you know if your protein binded to the column? How would you modify the purification next time to make it more efficient?
In analyzing the column percents, do you detect a consistent tendency for the column percents to...
In analyzing the column percents, do you detect a consistent tendency for the column percents to get either larger or smaller as you scan across the top row?
Excel sorting In excel how do you sort a column of months in ascending order and...
Excel sorting In excel how do you sort a column of months in ascending order and not alphabetical when the month is in word format?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT