gzc
gzc

Reputation: 8599

Get None after set_index for empty DataFrame

>>> pd.DataFrame(get_pe(symbol, start_time, end_time), columns=['time', 'pe'])
Empty DataFrame
Columns: [time, pe]
Index: []
>>> pd.DataFrame(get_pe(symbol, start_time, end_time), columns=['time', 'pe']).set_index('time', inplace=True)
None

Is there a way to get empty DataFrame with set index instead of None?

Upvotes: 0

Views: 666

Answers (1)

Randy
Randy

Reputation: 14847

You're getting None because of the inplace=True, not because of the empty DataFrame:

In [46]: pd.DataFrame(columns=["a", "b"]).set_index("a", inplace=True)

In [47]: pd.DataFrame(columns=["a", "b"]).set_index("a")
Out[47]:
Empty DataFrame
Columns: [b]
Index: []

Upvotes: 1

Related Questions