1

I need to import multiple .csv into one dataframe. Each of the .csv files have the same number of columns and same name of columns. The first columns is x, and the all other n columns are y. Every x column start with 0, continue with some step, eg. = 0.5 or 0.25 and end to the length of the column. When i join the multiple files i want the second file to continue from last value from the first file + time step, and same for the third, fourth and n-th .csv file.

I used a code for loading multiple .csv files in dataframe from:

Import multiple csv files into pandas and concatenate into one DataFrame

Here a two images that describe my problem:

This is what i get if the column values are retain after the loading of each .csv file: https://i.stack.imgur.com/BzqKa.jpg

This is what i need to achieve: https://i.stack.imgur.com/Q8o6X.jpg

CSV files:

sharecsv.com/s/14b6f07c30a95080c911da98d6017a2a/test1.csv sharecsv.com/s/a7463838fb74d42c603c407ef9f904dd/test2.csv sharecsv.com/s/6dbebaef902ca916bdb93b51c34f1a82/test3.csv sharecsv.com/s/a52562cbf5be32026644befda5d66139/test4.csv

Below you can find my code and the manual solution which i want to automate:

# Importing the Libraries:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
import glob

# Importing Multiple Data:

path = r'C:\Users\All...'   
all_files = glob.glob(os.path.join(path, "*.csv"))

df_from_each_file = (pd.read_csv(f) for f in all_files)
df = pd.concat(df_from_each_file, ignore_index=True)

# Plot 1

plt.plot(df["x"], df["y1"], "r")

# Replace X values (manualy)

dt = df["x"][1]-df["x"][0] # Time step (Manualy added)
n = pd.Series(np.arange(0, len(df["y1"])))*dt # n is replacing x in df
df["x"] = n

# Plot 2

plt.plot(df["x"], df["y1"], "b")

Thanks in advance!

phoenix_dj
  • 25
  • 6

0 Answers0