Python Forum
concat 3 columns of dataframe to one column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
concat 3 columns of dataframe to one column
#1
Hi,
I've got a dataframe with 100 rows and 3 columns (please see attachment).

How can I concate the 3 columns to one column?

Per example the 3 elements of the first row (255 255 255) should be 1 element (255255255) and so on.

import numpy as np
import pandas as pd
from PIL import Image

colorImage = Image.open("p2.bmp")
colorPixels = colorImage.convert('RGB')
# Make into array
colorArray = np.array(colorPixels.getdata())
df = pd.DataFrame(colorArray)
print(df)
df2 = pd.concat(df["0"], df["1"], df["2"])
print(df2)
Thanks a lot for your help!!

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
concat 3 columns of dataframe to one column - by flash77 - Oct-03-2023, 08:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add columns to polars dataframe sayyedkamran 1 1,858 Nov-03-2023, 03:01 PM
Last Post: gulshan212
  HTML Decoder pandas dataframe column mbrown009 3 1,110 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  attempt to split values from within a dataframe column mbrown009 8 2,444 Apr-10-2023, 02:06 AM
Last Post: mbrown009
  New Dataframe Column Based on Several Conditions nb1214 1 1,836 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Putting column name to dataframe, can't work. jonah88888 1 1,863 Sep-28-2021, 07:45 PM
Last Post: deanhystad
  Setting the x-axis to a specific column in a dataframe devansing 0 2,063 May-23-2021, 12:11 AM
Last Post: devansing
  Convert several columns to int in dataframe Krayna 2 2,448 May-21-2021, 08:55 AM
Last Post: Krayna
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 2,310 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 3,345 May-09-2021, 06:46 PM
Last Post: Pit292
  Outputs "NaN" after "DataFrame columns" function? epsilon 7 3,725 Jan-27-2021, 10:59 AM
Last Post: epsilon

Forum Jump:

User Panel Messages

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