Semitron
Semitron

Reputation: 134

Why does the dataframe not display a table with the same columns?

I came across such a case. there is a data frame with the same columns and does not output the entire table.

My code:

import pandas as pd
data = {2:['Green','Blue'],
        2:['small','BIG'],
        2:['High','Low']}
df = pd.DataFrame(data)
print(df)

Output:

      2
0  High
1   Low

Upvotes: 1

Views: 579

Answers (1)

Vinay
Vinay

Reputation: 136

Dictionary only supports Unique Keys (in Key-Value pairs) So when you create a DataFrame using Dictionary, it will only consider the latest Key-Value pair if there is duplication in Key. For any reason, you create DataFrame with the Same Column Headers, use following code -

import pandas as pd
df = pd.DataFrame([['Green','Blue'], ['small','BIG'], ['High','Low']], columns = [2,2])
print(df)

It will show entire table with same column headers

Upvotes: 1

Related Questions