Dołączanie do pustej ramki danych w Pandzie?

Czy jest możliwe dołączenie do pustej ramki danych, która nie zawiera żadnych indeksów ani kolumn?

Próbowałem to zrobić, ale na końcu otrzymuję pustą ramkę danych.

Np.

df = pd.DataFrame()
data = ['some kind of data here' --> I have checked the type already, and it is a dataframe]
df.append(data)

Wynik wygląda następująco:

Empty DataFrame
Columns: []
Index: []
 119
Author: ericmjl, 2013-05-17

3 answers

To powinno zadziałać:

>>> df = pd.DataFrame()
>>> data = pd.DataFrame({"A": range(3)})
>>> df.append(data)
   A
0  0
1  1
2  2

Ale append nie dzieje się na miejscu, więc musisz zapisać wyjście, jeśli chcesz:

>>> df
Empty DataFrame
Columns: []
Index: []
>>> df = df.append(data)
>>> df
   A
0  0
1  1
2  2
 227
Author: DSM,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-16 20:58:48

I jeśli chcesz dodać wiersz, możesz użyć słownika:

df = pd.DataFrame()
df = df.append({'name': 'Zed', 'age': 9, 'height': 2}, ignore_index=True)

Co daje:

   age  height name
0    9       2  Zed
 70
Author: dval,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-05 17:38:03

Możesz połączyć dane w ten sposób:

InfoDF = pd.DataFrame()
tempDF = pd.DataFrame(rows,columns=['id','min_date'])

InfoDF = pd.concat([InfoDF,tempDF])
 11
Author: Deepish,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-12 12:15:25