-2

I have a dataframe (25000, 20000). The original format is like this enter image description here

I would like to make it become like this

enter image description here

by using python. Can anyone give a help?

Mehmaam
  • 573
  • 7
  • 22
thdk13
  • 1
  • 2

1 Answers1

0

Try this; Assuming you wish to have the last column be part of your final data without any column name...

df = pd.DataFrame({"":[1,2,3],
                   "a":[4,5,6],
                   "b":[7,8,9]})

a = ""
df.columns = list(df.columns[1:]) + [a]

# Output of df;
   a  b   
0  1  4  7
1  2  5  8
2  3  6  9
Sachin Kohli
  • 1,956
  • 1
  • 1
  • 6
  • Thank you. Actually I would like to save it in txt file, with the last column name is NULL. In your example, the "column_name" must be disappear. – thdk13 Sep 30 '22 at 09:09
  • So, "column_name" must be disappear... I'm assuming you don't wish to have this column in final dataset... & have edited the code accordingly... Hope this Helps... – Sachin Kohli Sep 30 '22 at 09:55
  • Thank you. But in the txt file, I still want to keep the last column's value (7 8 9), but it's name is NULL. I'm trying to do open a new file and write every single row to it, but still not work. – thdk13 Sep 30 '22 at 10:25
  • Ok... Edited answer again... Last column will be there & column name will be the value of variable "a"... Feel free to edit the variable "a" to see the change in column name of last variable... – Sachin Kohli Sep 30 '22 at 10:31