I have the following nested dictionary:
table_dict = {
"ints": {
"domain highlights": {
"rows": 3000000,
"nulls": 5
},
"range metrics": {
"mean": 0,
"maximum": 0,
"minimum": 0
},
"focus values": {
"1": 0,
"sample_text": 0
}
},
"strings": {
"domain highlights": {
"rows": 3000000,
"nulls": 5
},
"range metrics": {
"mean": 0,
"maximum": 0,
"minimum": 0
},
"focus values": {
"1": 0,
"sample_text": 0
}
},
"floats": {
"domain highlights": {
"rows": 3000000,
"nulls": 5
},
"range metrics": {
"mean": 0,
"maximum": 0,
"minimum": 0
},
"focus values": {
"1": 0,
"sample_text": 0
}
}
}
When I run this line
table_dict["ints"]["range metrics"]["mean"] = 11
it changes all the "mean" values instead of just the mean in the "ints" dict. Here is what my dict looks like after that line
table_dict = {
"ints": {
"domain highlights": {
"rows": 3000000,
"nulls": 5
},
"range metrics": {
"mean": 11,
"maximum": 0,
"minimum": 0
},
"focus values": {
"1": 0,
"sample_text": 0
}
},
"strings": {
"domain highlights": {
"rows": 3000000,
"nulls": 5
},
"range metrics": {
"mean": 11,
"maximum": 0,
"minimum": 0
},
"focus values": {
"1": 0,
"sample_text": 0
}
},
"floats": {
"domain highlights": {
"rows": 3000000,
"nulls": 5
},
"range metrics": {
"mean": 11,
"maximum": 0,
"minimum": 0
},
"focus values": {
"1": 0,
"sample_text": 0
}
}
}
How do I only change one value instead of over-writing all of them. Is there a separate way to change the values of dictionaries that I need to use?
For the person asking how I first created table_dict:
focus_values = [1, "sample_text"]
table_name = ""
setup = True
col_dict = {"domain highlights": {"rows": 0, "nulls": 0},
"range metrics": {"mean": 0, "maximum": 0, "minimum": 0},
"focus values": {}}
for i in focus_values:
col_dict["focus values"][i] = 0
file = "large_sample_file.csv"
file_df = pd.read_csv(file, chunksize=10000)
for chunk in file_df:
if setup:
setup = False
table_name = chunk.iloc[1, 0] # table name is in column 1
table_dict = {}
for i in chunk.columns[1:]:
table_dict[i] = col_dict
profile_table(chunk, table_dict)