PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 13, 2022

[FIXED] How to append a list to dataframe without using column names?

 May 13, 2022     append, pandas, python     No comments   

Issue

I want to append a list of four prices [1, 2, 3, 4] to an already existing dataframe using the DataFrame.append(), the already existing dataframe has four columns.

Using this

dataframe = pd.DataFrame(columns=["open", "high", "low", "close"],
                         data = [[1, 2, 3, 4]])

Creates the dataframe

   open  high  low  close
0     1     2    3      4

Then I want to append some lists like this:

dataframe = dataframe.append([[5, 6, 7, 8]],
                             ignore_index =True)

Gives the output

   open  high  low  close    0    1    2    3
0   1.0   2.0  3.0    4.0  NaN  NaN  NaN  NaN
1   NaN   NaN  NaN    NaN  5.0  6.0  7.0  8.0

While I want the list to be appended in continuation to the dataframe, is there a way to do this without using the column names, only the list of four prices?


Solution

You can do something like

df.loc[len(df)] = [1, 2, 3, 4]


Answered By - Slayer
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing