Python Forum
Dividing a single column of dataframe into multiple columns based on char length
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dividing a single column of dataframe into multiple columns based on char length
Hi Guys,
I am importing a dataset from a url using below function:
## Import from the url
import pandas as pd
print (dftemp)
print (type(dftemp))
It works fine and give me a result like:
aris km 21 1 0 aris km 21 2 1 aris km 21 3 2 aris km 21 4 6183 sovr va 100 1439 6184 sovr va 101 1440 [6185 rows x 1 columns] <class 'pandas.core.frame.DataFrame'> #########
my objective:
I want to divide this single column in multiple columns -- eg.. for first row ----first column is for "aris km", 2nd for 21 and third for 1 . This should be based on the characters, like first value "aris km or sovr va is confined within 6 characters -- then 21 is occupying between 8-14 characters and last one is occupying 16 to 18 characters.

If I use split function, I will be able to break it using the space and thus 'aris" and 'km" will also be different columns while it should be same column.

How to break in this way?

Messages In This Thread
Dividing a single column of dataframe into multiple columns based on char length - by darpInd - Mar-13-2020, 11:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New Dataframe Column Based on Several Conditions nb1214 1 371 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Putting column name to dataframe, can't work. jonah88888 1 572 Sep-28-2021, 07:45 PM
Last Post: deanhystad
  update values in one dataframe based on another dataframe - Pandas iliasb 2 2,148 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  Pandas Data frame column condition check based on length of the value aditi06 1 850 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  Setting the x-axis to a specific column in a dataframe devansing 0 864 May-23-2021, 12:11 AM
Last Post: devansing
  Convert several columns to int in dataframe Krayna 2 842 May-21-2021, 08:55 AM
Last Post: Krayna
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 969 May-17-2021, 07:02 AM
Last Post: lorensa74
  iretate over columns in df and calculate euclidean distance with one column in pandas Pit292 0 1,211 May-09-2021, 06:46 PM
Last Post: Pit292
  Add column based on others timste 8 1,669 Apr-03-2021, 07:39 AM
Last Post: devesh_sahu
  Outputs "NaN" after "DataFrame columns" function? epsilon 7 1,468 Jan-27-2021, 10:59 AM
Last Post: epsilon

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020