squirrelyMoEco
squirrelyMoEco

Reputation: 11

ParserWarning and Future Warning Python Errors

I am attempting to run a python code to rearrange some of my files:

import glob
import pandas as pd
import numpy as np
files = glob.glob('*.txt')
result = pd.DataFrame()
for file in files:
    df = pd.read_csv(file,delimiter='  ')
    current_col = df.columns[0]
    df.reset_index(inplace=True)
    df.set_index(current_col,inplace=True)
    df.index.name = 'index'
    df.rename(columns={'index':current_col}, inplace=True)
    result = pd.concat([result,df],axis=1)

But am getting this error:

file4.py:9: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'. df = pd.read_csv(file,delimiter=' ') file4.py:15: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version of pandas will change to not sort by default. To accept the future behavior, pass 'sort=False'. To retain the current behavior and silence the warning, pass 'sort=True'. result = pd.concat([result,df],axis=1)

So, I attempted adding the engine='python' as suggested:

import glob
import pandas as pd
import numpy as np
engine='python'
files = glob.glob('*.txt')
result = pd.DataFrame()
for file in files:
    df = pd.read_csv(file,delimiter='  ')
    current_col = df.columns[0]
    df.reset_index(inplace=True)
    df.set_index(current_col,inplace=True)
    df.index.name = 'index'
    df.rename(columns={'index':current_col}, inplace=True)
    result = pd.concat([result,df],axis=1)

But this did not fix the issue. And I am not finding a remedy in previous posts (running on different python versions, etc). Does anyone have any other suggestions? Thanks for the help!

Upvotes: 0

Views: 636

Answers (1)

Rajas MR
Rajas MR

Reputation: 1

I tried giving engine='python' argument while loading the csv

df = pd.read_csv("file.csv", sep = "    ", engine='python')

Upvotes: 0

Related Questions