1
I am new in Python and Pandas I have a DF that with 3 columns, as in the example below:
SRC Data1 Data2 AAA 180 122 BBB 168 121 CCC 165 147 DDD 140 156 EEE 152 103 AAA 170 100 CCC 166 112 DDD 116 155 EEE 179 119
What I need is for a new DF to be created for each value that is in SRC, for example:
DF_A
SRC Data1 Data2 AAA 180 122 AAA 170 100
DF_B
SRC Data1 Data2 BBB 168 121
and so forth in all the values that there are in SRC, what I did was create a DF with the unique values of SRC
pd.DataFrame(DataFrameBase.SRC.unique())
but I don’t know if this is really gonna help me!
Thanks for your help!
Cara ta lindo! To close, how would I stop instead of print save new DF?
– Felipe Amaral Rodrigues
if you used the array, each position of the array has a dataframe, or if you used only the
df_a
and thedf_b
both are dataFrames, in the dataframe you can save them ascsv
orxlsx
by commandto_csv
orto_excel
for example:df_a.to_csv('df_a.csv')
ordf_b.to_excel('df_a.xlsx')
, it will save the file in the same folder where the app is, but you can also pass the full path for exampleC:/.../file.cls
– brow-joe
And how would I save the arrays? I tried the . to_csv but it didn’t work, I know I’m asking a lot, but I’m starting now with pandas.
– Felipe Amaral Rodrigues
imagine, the Voce array will need to do the foreach more before it is better to create an index to name the files:
index = 0
You do what you dofor data in dataFrames:
now inside the for vc will go through all the dataFrames, they are stored in date, now Voce can dodata.to_csv('dataFrame_' + str(index) + '.csv')
after this line you need to increment the Dice to the next fileindex += 1
– brow-joe
dude THANK YOU VERY MUCH
– Felipe Amaral Rodrigues