-2

I am new to hands-on python and programming in general. I have imported a 6gb pickle file into pandas and been able to display the results of the file. It doesn't look well ordered however. My dataframe has varying rows and 842 columns. My next task is to;

  • get column names of all 842 columns so i can find columns that have similar features.
  • create a new column (series) with data from (1) above
  • "append" new column to original dataframe

Thus far i have tried the "functions" column, col, dataframe.columns, to get column names but no one is working.

Please see what my program looks like;code and output

1 Answers1

0

You can get list of your dataframe column names using this :

list(your_dataframe.columns)

for adding new columns, check this : new-columns-in pandas

FoCDoT
  • 63
  • 5
  • Thanks. Tried that -- list(df.columns)-- but it sees "df" as a 'dict' instead of a dataframe. Which means i should try converting df to a dataframe, yes? – Nobinwanne Oct 28 '21 at 14:32
  • According to the error in the image, there is a typo in your code, you should use: print(df.columns) instead of print(Dataframe.columns) – saeedhosseini Oct 28 '21 at 14:41
  • df should be a dataframe not a dict. please check this --print(type(df))-- – saeedhosseini Oct 28 '21 at 14:43
  • Hi @saeed, i've tried print(type(df)) and it's shown that df is a dict. . So now i need help with converting this dict to a dataframe. – Nobinwanne Oct 28 '21 at 14:49
  • okay so do this : data=pd.DataFrame(d.items()) note that d is your dictionary, it should work – saeedhosseini Oct 28 '21 at 15:36
  • Thank you Saeed. Yes, it worked. The read_pickle() call returned a list of dataframes that's why 'df' was seen as a dictionary. data=pd.DataFrame(d.items()) display(data) Displays the list of dataframes. From here I need to display each list's dataframe to find the columns i'm looking for. – Nobinwanne Oct 28 '21 at 16:47