Reputation: 6968
I'm trying to create a DataFrame with 3 columns, but for some reason - only one column is being added:
# Create a new DataFrame from our transformed data
stock_incident_df = pd.DataFrame(stock_incident_data, columns=['date', 'number_of_incidents', 'stock_price_close'])
print(stock_incident_df.describe())
number_of_incidents
count 1551.000000
mean 154.629916
std 25.782985
min 77.000000
25% 137.000000
50% 154.000000
75% 171.000000
max 342.000000
Even if I separate the constructor and appending the data, the issue comes up:
stock_incident_df = pd.DataFrame(columns=['date', 'number_of_incidents', 'stock_price_close'])
print(stock_incident_df.describe())
stock_incident_df = stock_incident_df.append(stock_incident_data)
print(stock_incident_df.describe())
date number_of_incidents stock_price_close
count 0 0 0
unique 0 0 0
top NaN NaN NaN
freq NaN NaN NaN
1
count 1551.000000
mean 154.629916
std 25.782985
min 77.000000
25% 137.000000
50% 154.000000
75% 171.000000
max 342.000000
My input data is a list of lists with the following format:
[
[Timestamp('2014-01-02 00:00:00'), 119, 16441.35],
[Timestamp('2014-01-03 00:00:00'), 124, 16469.99],
[Timestamp('2014-01-06 00:00:00'), 100, 16425.11],
[Timestamp('2014-01-07 00:00:00'), 115, 16530.94]
]
Upvotes: 0
Views: 40
Reputation: 6968
My mistake - the describe()
method doesn't include the date in it's output, simply printing the DataFrame shows the data:
stock_incident_df = pd.DataFrame(stock_incident_data, columns=['date', 'number_of_incidents', 'stock_price_close'])
print(stock_incident_df)
date ... stock_price_close
0 2014-01-02 ... 16441.3
1 2014-01-03 ... 16470
2 2014-01-06 ... 16425.1
3 2014-01-07 ... 16530.9
4 2014-01-08 ... 16462.7
... ... ... ...
1546 2018-03-18 ... 31585 24946.51
Name: Close, dtype: float64
1547 2018-03-24 ... 31590 23533.2
Name: Close, dtype: float64
1548 2018-03-25 ... 31590 23533.2
Name: Close, dtype: float64
1549 2018-03-30 ... 31594 24103.11
Name: Close, dtype: float64
1550 2018-03-31 ... 31594 24103.11
Name: Close, dtype: float64
[1551 rows x 3 columns]
Upvotes: 0
Reputation: 688
is correctly imported Timestamp? If using pd.Timestamp it seems to work.
import pandas as pd
stock_incident_data=[
[pd.Timestamp('2014-01-02 00:00:00'), 119, 16441.35],
[pd.Timestamp('2014-01-03 00:00:00'), 124, 16469.99],
[pd.Timestamp('2014-01-06 00:00:00'), 100, 16425.11],
[pd.Timestamp('2014-01-07 00:00:00'), 115, 16530.94]
]
stock_incident_df = pd.DataFrame(stock_incident_data, columns=['date', 'number_of_incidents', 'stock_price_close'])
stock_incident_df
Out[17]:
date number_of_incidents stock_price_close
0 2014-01-02 119 16441.35
1 2014-01-03 124 16469.99
2 2014-01-06 100 16425.11
3 2014-01-07 115 16530.94
Upvotes: 1