Save csv files to Python after making changes?

Asked

Viewed 2,959 times

0

I am making some changes to multiple csv files at once, and would like to know how to save the output to a single file.

import pandas as pd
dataset = pd.read_csv('Downloads/Dados_PNBoia/teste/*.csv')
dataset.loc[(dataset[' yyyy']==2018) & (dataset[' temp']!=-99999)]
dataset['size'] = (dataset[' temp']+273.15) #também não consegui fazer esse acréscimo na coluna, após filtra-la

What can be done to miss this file? P.S.: I tried to add an amount to column ' temp' after filtering, but it does not come out with the new value. Thank you in advance!

1 answer

0


Hello,

You can concatenate your dataframe to have a single dataframe. For example:

df1 = pd.read_csv('arq01.csv')
df2 = pd.read_csv('arq02.csv')

df3 = pd.concat([df1,df2], ignore_index=True)

Then you make your filters and then save your dataframe in a single file, this way:

df3.to_csv('file.csv')
  • It didn’t work. It gathers all the data but not the ones I wanted to filter. It comes all the original data.

  • I got it, I just tweaked a part and he saved it right. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.