I'm trying to separate my data into into multiple dataframes.
It didn't work because '.com', '.us', '.de', '.in' etc. domains are not being recognized by python.
Please suggest a way to
I converted groupby object to tuples and then to dict.
d = dict(tuple(df.groupby('Site')))
for i, g in df.groupby('Site'):
globals()['df_' + str(i)] = g
print (df_xyz.com)
Error message says:
AttributeError: 'DataFrame' object has no attribute 'xyz'
What I'm trying to achieve here is, to export these mutiple dataframes into a workbook with multiple sheets like xyz.com, xyz.us, xyz.in etc.
Perhaps the error is that you are attempting to create a variable with '.' in the name, which is not allowed in Python. May I suggest:
d = dict(tuple(df.groupby('Site')))
for i, g in df.groupby('Site'):
globals()['df_' + str(i).replace('.','_')] = g
print (df_xyz_com)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.