how to split 'number' to separate columns in pandas DataFrame

Heisenberg

I have a dataframe;

df=pd.DataFrame({'col1':[100000,100001,100002,100003,100004]})

     col1    
0   100000    
1   100001
2   100002
3   100003
4   100004

I wish I could get the result below;

    col1   col2    col3
0   10     00       00 
1   10     00       01
2   10     00       02
3   10     00       03
4   10     00       04

each rows show the splitted number. I guess the number should be converted to string, but I have no idea next step.... I wanna ask how to split number to separate columns.

benten
# make string version of original column, call it 'col'
df['col'] = df['col1'].astype(str)

# make the new columns using string indexing
df['col1'] = df['col'].str[0:2]
df['col2'] = df['col'].str[2:4]
df['col3'] = df['col'].str[4:6]

# get rid of the extra variable (if you want)
df.drop('col', axis=1, inplace=True)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to split a pandas dataframe into multiple columns

From Dev

Pandas Series str.split assign the split result back to the original dataframe as separate columns

From Dev

How to split a column into two separate ones in a DataFrame with Pandas

From Dev

How to split a dataframe column into multiple columns with a Pandas converter

From Dev

How to split a pandas dataframe into many columns after groupby

From Dev

How do I split a string into several columns in a dataframe with pandas Python?

From Dev

Reduce number of columns in a pandas DataFrame

From Dev

How to split columns of a CSV file into separate files?

From Dev

How to split columns of a CSV file into separate files?

From Dev

how to split date and time and create separate columns

From Dev

How to count the number of persons with values present in n columns of a pandas dataframe

From Java

split multiple columns in pandas dataframe by delimiter

From Dev

Pandas Dataframe - Split string into multiple columns

From Dev

Split list in Pandas dataframe column into multiple columns

From Dev

Split pandas dataframe column based on number of digits

From Dev

Print columns of Pandas dataframe to separate files + dataframe with datetime (min/sec)

From Dev

Split Columns into separate variables

From Dev

Split column into separate columns

From Dev

How to split Dataframe using pandas

From Dev

How to make 18 separate scatterplots for 18 different columns from the same pandas Dataframe?

From Dev

how can I split a dataframe by two columns and count number of rows based on group more efficient

From Dev

Split Pandas Dataframe into separate pieces based on column values

From Dev

Split Pandas Dataframe into separate pieces based on column values

From Dev

Number of levels (depth) of index and columns in a Pandas DataFrame

From Dev

pandas dataframe drop columns by number of nan

From Dev

Restructuring pandas dataframe based on number of columns

From Dev

Pandas Dataframe Transpose to varying number of columns

From Dev

Dropping a number of columns in a pandas DataFrame on one line

From Dev

How to split dataframe or reorder dataframe by rows in pandas

Related Related

  1. 1

    How to split a pandas dataframe into multiple columns

  2. 2

    Pandas Series str.split assign the split result back to the original dataframe as separate columns

  3. 3

    How to split a column into two separate ones in a DataFrame with Pandas

  4. 4

    How to split a dataframe column into multiple columns with a Pandas converter

  5. 5

    How to split a pandas dataframe into many columns after groupby

  6. 6

    How do I split a string into several columns in a dataframe with pandas Python?

  7. 7

    Reduce number of columns in a pandas DataFrame

  8. 8

    How to split columns of a CSV file into separate files?

  9. 9

    How to split columns of a CSV file into separate files?

  10. 10

    how to split date and time and create separate columns

  11. 11

    How to count the number of persons with values present in n columns of a pandas dataframe

  12. 12

    split multiple columns in pandas dataframe by delimiter

  13. 13

    Pandas Dataframe - Split string into multiple columns

  14. 14

    Split list in Pandas dataframe column into multiple columns

  15. 15

    Split pandas dataframe column based on number of digits

  16. 16

    Print columns of Pandas dataframe to separate files + dataframe with datetime (min/sec)

  17. 17

    Split Columns into separate variables

  18. 18

    Split column into separate columns

  19. 19

    How to split Dataframe using pandas

  20. 20

    How to make 18 separate scatterplots for 18 different columns from the same pandas Dataframe?

  21. 21

    how can I split a dataframe by two columns and count number of rows based on group more efficient

  22. 22

    Split Pandas Dataframe into separate pieces based on column values

  23. 23

    Split Pandas Dataframe into separate pieces based on column values

  24. 24

    Number of levels (depth) of index and columns in a Pandas DataFrame

  25. 25

    pandas dataframe drop columns by number of nan

  26. 26

    Restructuring pandas dataframe based on number of columns

  27. 27

    Pandas Dataframe Transpose to varying number of columns

  28. 28

    Dropping a number of columns in a pandas DataFrame on one line

  29. 29

    How to split dataframe or reorder dataframe by rows in pandas

HotTag

Archive