Creating a single line string python pandas dataframe

I want to create a python pandas DataFrame with one row to use additional pandas functions like dumping to * .csv.

I saw that the following code is used, but I only get the column structure, but empty data

import pandas as pd df = pd.DataFrame() df['A'] = 1 df['B'] = 1.23 df['C'] = "Hello" df.columns = [['A','B','C']] print df Empty DataFrame Columns: [A, B, C] Index: [] 

As long as I know that there are other ways to do this (for example, from a dictionary), I want to understand why this piece of code does not work for me !? Is this a problem with the version? (using pandas == 0.19.2)

+5
source share
1 answer
 In [399]: df = pd.DataFrame(columns=list('ABC')) In [400]: df.loc[0] = [1,1.23,'Hello'] In [401]: df Out[401]: ABC 0 1 1.23 Hello 

or

 In [395]: df = pd.DataFrame([[1,1.23,'Hello']], columns=list('ABC')) In [396]: df Out[396]: ABC 0 1 1.23 Hello 
+8
source

Source: https://habr.com/ru/post/1270578/


All Articles