+ 1

list object is not callable (for dataframe)

data = [{'a': i, 'b': 2 * i} for i in range(3)] df = pd.DataFrame(data) print(df) when i call this DataFrame i obtain this result.... why?

6th Jun 2020, 4:37 PM
Daniele Baldoni
Daniele Baldoni - avatar
5 Antworten
+ 6
ChaoticDawg, you are wrong, pandas can use this dict without any problems. It's exactly as i mentioned: insert the import statement and the code does run. I am sure you did not try it. Just copy / paste the code in playground...
7th Jun 2020, 5:13 PM
Lothar
Lothar - avatar
+ 5
You missed to import pandas. Make this as first line in code: import pandas as pd
6th Jun 2020, 6:05 PM
Lothar
Lothar - avatar
+ 4
Lothar You're correct, I did not try it. I haven't really used Pandas much and every example and explanation I have seen shows only the options I mentioned. I just thought that only part of the code was shown. So if it works with the import great. That's why I said "I don't think" lol, leaving room for error, because I wasn't sure if the answer was 100% correct. Just wanted to give some information that may have been a possible issue. I didn't try it, like I usually would, because this app has been crap for me lately taking several seconds to minutes for things to load/reload with a good internet connection. Very frustrating. But thanks for the info.
7th Jun 2020, 6:59 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
I don't think a list of dictionaries is a valid data format for the the Pandas DataFrame method. You can use a two dimensional list, tuple, Numpy array or a dictionary where the key is the column name and the value is a list of the values in that column or a Pandas Series. https://realpython.com/pandas-dataframe/
6th Jun 2020, 6:08 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Thank you Lothar.... I re-tried with import pandas in The same block of code.... I wrote it in another block before. That was the key :)
7th Jun 2020, 6:58 PM
Daniele Baldoni
Daniele Baldoni - avatar