In [37]: blue = pd.DataFrame({'A': ['foo','foo','foo','bar','bar'], 'B': [4.0, 4.0, 5.0, 8.0, 8.0]})
In [38]: blue
Out[38]:
A B
0 foo 4
1 foo 4
2 foo 5
3 bar 8
4 bar 8
In [39]: red = pd.DataFrame({'A': ['foo','foo','foo','bar','bar'], 'B': [np.nan, np.nan, np.nan, np.nan, np.nan]})
In [40]: red
Out[40]:
A B
0 foo NaN
1 foo NaN
2 foo NaN
3 bar NaN
4 bar NaN
In [41]: for df in [blue, red]:
....: df.to_csv(str(df))
....:
In [42]: !ls
A B?0 foo 4?1 foo 4?2 foo 5?3 bar 8?4 bar 8 A B?0 foo NaN?1 foo NaN?2 foo NaN?3 bar NaN?4 bar NaN postinstall.sh vagrant
I have some DataFrames. I loop over each DataFrame to work on them. At the end of the loop I want to save each DataFrame as a .csv file named after the DataFrame. I know that it's generally difficult to stringify the name of a variable in Python, but I have to think that I'm missing something obvious here. There is no "name" attribute for DataFrames, so what do I do?