我認爲你可以使用DataFrame.from_records
與轉換tuples
到list
:
import pandas as pd
tuples = ((1,2,3),(4,6,7),(7,3,6),(8,2,7),(4,6,3),(7,3,6))
columnlist = ['a','b','c']
df = pd.DataFrame.from_records(list(tuples), columns=columnlist)
print (df)
a b c
0 1 2 3
1 4 6 7
2 7 3 6
3 8 2 7
4 4 6 3
5 7 3 6
只有DataFrame
構造另一種解決方案:
import pandas as pd
tuples = ((1,2,3),(4,6,7),(7,3,6),(8,2,7),(4,6,3),(7,3,6))
columnlist = ['a','b','c']
df = pd.DataFrame(list(tuples), columns=columnlist)
print (df)
a b c
0 1 2 3
1 4 6 7
2 7 3 6
3 8 2 7
4 4 6 3
5 7 3 6
編輯:
如果檢查DataFrame
和參數data
:
data : numpy ndarray (structured or homogeneous), dict, or DataFrame
Dict can contain Series, arrays, constants, or list-like objects
我使用以下代碼 columnlist = [ 「時間戳」, 「價格」, 「月」, 「日」, 「星期幾」, 「tDaysleftMonth」, 「tDayinMonth」, 「tDayinWeek」] tickerData = pd.DataFrame(tickerDataRaw,columns = columnlist) –
如果我的回答很有幫助,請不要忘記[接受](https://stackoverflow.com/help/someone-answers) - 點擊複選標記('v ')旁邊的答案切換從灰色到填充。謝謝。 – jezrael